A brief list of git commands

11 Dec


git fetch origin
(origin is the serve alias)
Looks up which server is origin; –>
fetches any data you don’t have—>
update local data base –>
moving the origin/master pointer to up-to-date position

image   image

The above figures are copied from Git Pro book, see here for details.

git push origin WhichBranch

git push origin LocalBranch:RemoteBranch

Take the local branch(Which Branch) ; –> push and update remote’s WhichBranch

Take the local branch ; –> push and update remote’s RemoteBranch

after pushing YourBranch to the server, other people can run “git fetch origin” to get this branch. It’s important to note that when they do a fetch that brings down new remote branches, they don’t automatically have local, editable copies of them. In other words, in this case, they don’t have a new YourBranch branch — you only have an origin/YourBranch pointer that can’t be modified.


git checkout master                           //switch to master branch
git reset –hard origin/master           //reset to remote’s master branch
git push origin HEAD:YourBranch   //create a new branch named “YourBranch”

See also a very good blog at

To merge this work into your current local branch, use

git merge origin/ServerBranch Merge server’s ServerBranch to your current working branch
git checkout –b [BranchName] [RemoteName/BranchName] Get a local, editable BranchName from the server


git add SomeFile Add SomeFile to make it staged/cached/indexed
git rm SomeFile Remove the already committed file from repository, and also remove it in OS file system (or working directory)
git rm –cached SomeFile Unstage the file from index, but NOT remove it from OS file system
git ls-files –stage List files that are staged/cached, but not committed yet, with information such as SHA1 cache, file name etc.
git ls-files –cached List files that are staged/cached,
git checkout HEAD — DeletedFileName Recover deleted file from local repository
git checkout HEAD~ — FileName Recover the commit earlier than the latest one
git checkout HEAD~5 — FileName Recover the 5 earlier commit than the latest one
git mv Source Target Rename a file
git log Get all the log of operation
git log SomeFile Get the log specific to a file
git show HEAD Display the latest commit
git show HEAD~ Display the last but one commit
gitk View commit graph

git reset –hard HEAD
git pull

verwrite of local files on a git pull

Leave a comment

Posted by on December 11, 2011 in Programming


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: