3
git init git status To tell Git to start tracking changes made to octocat.txt, we first need to add it to the staging area by using git add. git add octocat.txt we run the commit command with a message describing what we've changed git commit -m "Add cute octocat story" we can add all the new files using a wildcard with git add. Don't forget the quotes! git add '*.txt' This command takes a remote name and a repository URL, which in your case is https://github.com/try-git/try_git.git. Go ahead and run git remote add with the options below: git remote add origin https://github.com/try-git/try_git.git The name of our remote is origin and the default local branch name is master. The -u tells Git to remember the parameters, so that next time we can simply run git push and Git will know what to do. Go ahead and push it! git push -u origin master pull down any new changes git pull origin master we want the diff of our most recent commit, which we can refer to using the HEAD pointer. git diff HEAD

Git

  • Upload
    dimple

  • View
    6

  • Download
    2

Embed Size (px)

DESCRIPTION

Git Code help

Citation preview

Page 1: Git

git init

git status

To tell Git to start tracking changes made to octocat.txt, we first need to add it to the staging area by using git add.

git add octocat.txt

we run the commit command with a message describing what we've changed

git commit -m "Add cute octocat story"

we can add all the new files using a wildcard with git add. Don't forget the quotes!

git add '*.txt'

This command takes a remote name and a repository URL, which in your case is https://github.com/try-git/try_git.git.

Go ahead and run git remote add with the options below:

git remote add origin https://github.com/try-git/try_git.git

The name of our remote is origin and the default local branch name is master. The -u tells Git to remember the parameters, so that next time we can simply run git push and Git will know what to do. Go ahead and push it!

git push -u origin master

pull down any new changes

git pull origin master

we want the diff of our most recent commit, which we can refer to using the HEAD pointer.

git diff HEAD

Files can be changed back to how they were at the last commit by using the command: git checkout -- <target>. Go ahead and get rid of all the changes since the last commit for octocat.txt

git checkout -- octocat.txt

When developers are working on a feature or bug they'll often create a copy (aka. branch) of their code they can make separate commits to. Then when they're done they can merge this branch back into their main master branch.

Page 2: Git

We want to remove all these pesky octocats, so let's create a branch called clean_up, where we'll do all the work:

git branch clean_up

You can switch branches using the git checkout <branch> command. Try it now to switch to the clean_up branch:

git checkout clean_up

Alrighty, the moment has come when you have to merge your changes from the clean_up branch into the master branch. Take a deep breath, it's not that scary.

We're already on the master branch, so we just need to tell Git to merge the clean_up branch into it:

git merge clean_up

You can use git branch -d <branch name> to delete a branch. Go ahead and delete the clean_up branch now:

git branch -d clean_up

now is to push everything you've been working on to your remote repository, and you're done!

git push

• Go to the repository at https://github.ncsu.edu/csc517-f15/version-control • Use your unity id and password if asked to login

• Fork this repository by clicking on the Fork button in the top-right corner.• This creates a copy of this repository at

https://github.ncsu.edu/<your-unity-id>/version-control (e.g., https://github.ncsu.edu/nkdalmia/version-control)

• Clone repository• Open the command prompt (or terminal) and navigate to the directory where you

want to create the clone.• Run the clone command

• $ git clone https://github.ncsu.edu/<your-unity-id>/version-control.git • Use your unity id and password as credentials

• Now, there should be a folder version-control in the current directory. • Push Changes to Repository

• $ cd version-control• Make some changes in the file README.md• Stage your changes

• $ git add README.md• Commit your changes

• $ git commit –m “Updated README file”

Page 3: Git

• Push your changes• $ git push origin master

• Use your unity id and password as credentials