My personal Git cheat sheet

logo@2x

I think its important that everyone working with git to have his own cheat sheet with his own words and experiences, the following is my git cheat sheet.

 git clone <path> Clone an existing remote or local repository.
 git init Create a new local repository.
 git add <file> Add changes in “file” to index (the next commit) (stage) (track).
 git add . Add changes in current folder to index (stage) recursively. (.) means current directory.
 git status Display status of the current local branch.
 git status -s Summary display of status of local changes.
 git rm <file> Remove a file from index (if its already been deleted).
 git rm <file> –cached Remove a file from index keeping it in file system.
 git rm <file> -f Remove a file from index and file system (force removal).
 git diff Display changes to staged files.
 git commit -m <msg> Commit all staged files using commit massage.
 git commit -a -m <msg> Stage all changes in tracked files then commit using commit massage.
 git commit -am <msg> Stage all changes in tracked files then commit using commit massage.
 git log Display history of current branch starting with newest.
 git log -p <file> Display history of a specific file.
 git branch List all branches.
 git branch <branch> Create a new branch based on current branch.
 git checkout <branch> Switch to another branch (Switch HEAD).
 git checkout -b <branch> Switch to another branch and create the branch if its not created.
 git branch -d <branch> Delete a local branch.
 git remote Display existing remotes.
 git remote -v Display existing remotes verbose (including URLs)
 git remote add <name> <url> Add new remote providing a name and a url. (default name is origin).
 git fetch <remote> Download all changes from <remote>, but don’t integrate into HEAD.
 git push <remote> <branch> Publish local changes in <branch> to a remote <remote>.
 git push -u <remote> <branch> Publish local changes in <branch> to a remote <remote> and start tracking the remote branch.
 git pull <remote> <branch> Download changes in <remote> <branch> and directly merge/integrate into HEAD.
 git merge <branch> Merge <branch> into your current HEAD.
 git stash list Display a list of stashes.
 git stash Stash your current tracked changes and clean current workspace.
 git stash apply Apply the last stash to your current workspace.
 git stash pop Apply the last stash to your current workspace and delete the stash.
 git branch -d <branch> Delete the local branch X.
 git branch -dr <remote/branch> Delete the local tracking branch origin/X that tracks branch x.
 git push origin –delete <branch> Delete the remote branch X.
 git checkout <file> Discard local changes in a specific file.
 git reset HEAD <file> Unstage file, don’t include it in the commit.
 git revert <commit> Revert a commit by producing a new commit with contrary changes.
 git commit –amend –no-edit Change the last commit without changing commit massage (don’t use with published changes).
 git commit –amend -m <msg> Change the last commit and change commit massage (don’t use with published changes).
 git reset –hard HEAD  Discard all local changes in your working directory.
 git reset –hard <commit> Reset your HEAD pointer to a previous commit and discard all changes since then (don’t use with published changes).
 git reset <commit> Reset your HEAD pointer to a previous commit and preserve all changes as unstaged changes (don’t use with published changes).
 git reset –keep <commit> Reset your HEAD pointer to a previous commit and preserve uncommitted local changes (don’t use with published changes).
git ls-remote –tags origin List tags published (pushed) on remote (origin)

References:

http://git-scm.com/docs
https://www.atlassian.com/git/tutorials/rewriting-history
http://stackoverflow.com/questions/2003505/delete-a-git-branch-both-locally-and-remotely

Advertisements
This entry was posted in Software and tagged . Bookmark the permalink.

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s