Hardware Reference
In-Depth Information
Once that checkout succeeds, the code and files match that exact commit. If you look at the file system, you will
see your old files and old changes, but all will precisely match the first commit back form “ HEAD ”. The syntax “ HEAD
and “ ^ ” can be used with the diff command as well. To return to your latest status, issue the command:
$git checkout HEAD
Now your files and code match the official version.
One extremely useful use case is to check out just one file. You may have make changes you are not happy with,
and you will want to only grab an early version or the current version of file. You can use:
$git checkout - filename
This immediately checks out the previous version of the file. You can checkout the file from two versions ago by
using “HEAD~2”
$git checkout HEAD~2 filename
If the file didn't exists two version back it will complain file is not part of the commit.
You can also checkout what is called a branch:
$git branch HelloBranch
This command automatically creates a branch called “HelloBranch”, but does not switch to it.
$git checkout HelloBranch
This command will check out that branch. If you want to return to your “master” branch you can use:
$git checkout master
At some point you will want to know what branches you have. The command is:
$git branch
The result will list all the branches in your repository.
In our examples we don't cover branching, but you should learn about branching as you use GitHub. A branch
allows you to test out new ideas, create different versions of your project, or fix code without making changes in your
master branch. In this chapter, I only cover making changes to your “master” branch.
Move changes to your GitHub repository
Now that the changes are committed to the local repository, you need to push them to your GitHub repository, which
you can do by using the following command:
$ git push
If you are working on multiple machines, or multiple people are working with you, then your project on GitHub
could have changed. You may have even accepted a “pull request”. In this case, you will want to bring those changes,
or collection of commits, to your local repository. One method is to “fetch” the changes from GitHub. This grabs the
changes as a set, but does not merge them into your code automatically. The command would be as follows:
$ git fetch
Search WWH ::




Custom Search