Source: http://luisbg.blogalia.com/historias/76017
Configure
git config –global user.name "[name]"
Sets the name you want attached to your commit transactionsgit config –global user.email "[email address]"
Sets the email you want attached to your commit transactionsgit config –global color.ui auto
Enables helpful colorization of command line outputgit config –global push.default current
Update a branch with the same name as current branch if no refspec is givengit config –global core.editor [editor]
Which editor to use when commit and tag that lets you edit messagesgit config –global diff.tool [tool]
Specify which command to invoke as the specified tool for git difftool
Create repositories
git init [project-name]
Creates a new local repository with the specified namegit clone [url]
Downloads a project nd its entire version history
Make changes
git status
Lists all new or modified files to be committedgit status -s
Short view of statusgit diff
Shows file differences not yet stagedgit add [file]
Snapshots the file in preparation for versioninggit add .
Add all modified files to be commitedgit add '*.txt'
Add only certain filesgit add –patch filename.x (or -p for short)
Snapshot only chunks of a filegit rm [file]
Tell git not to track the file anymoregit diff –staged
Show what has been added to the index via git add but not yet committedgit diff HEAD
Shows what has changed since the last commit.git diff HEAD^
Shows what has changed since the commit before the latest commitgit diff [branch]
Compare current branch to some other branchgit difftool -d
Same as diff, but opens changes via difftool that you have configuredgit difftool -d master..
See only changes made in the current branchgit diff –no-commit-id –name-only –no-merges origin/master…
See only the file names that has changed in current branchgit diff –stat
See statistics on what files have changed and howgit reset [file]
Unstages the file, but preserves its contentsgit commit
Record changes to git. Default editor will open for a commit messagegit commit -m "[descriptive message]"
Records file snapshots permanently in version historygit commit –amend
Changing the history, of the HEAD commit
Group changes
git branch
Lists all local branches in the current directorygit branch [branch-name]
Create a new branchgit checkout [branch-name]
Switches to the specified branch and updates the working directorygit checkout -b <name> <remote>/<branch>
Switches to a remote branchgit checkout [filename]
Return file to it’s previous version, if it hasn’t been staged yetgit merge [branch]
Combines the specified branch’s history into the current branchgit merge –no–ff [branch]
Merge branch without fast forwardinggit branch -a
See the full list of local and remote branchesgit branch -d [branch]
Deletes the specified branchgit branch -D [branch]
Hard branch delete, will not complaingit branch -m <oldname> <newname>
Rename a branch
Refactor filenames
git rm [file]
Deletes the file from the working directory and stages the deletiongit rm –cached [file]
Removes the file from version control but preserves the file locallygit mv [file-original] [file-renamed]
Changes the file name and prepares it for commit
Suppress tracking
+ .gitignore \*.log build/ temp-\* A text file named .gitignore suppresses accidental versioning of files and paths
matching the specified patterns
git ls-files –other –ignored –exclude-standard
Lists all ignored files in this project
Save fragments
git stash
Temporarily stores all modified tracked filesgit stash pop
Restores the most recently stashed filesgit stash list
Lists all stashed changesetsgit stash drop
Discards the most recently stashed changeset
Review history
git log
Lists version history for the current branchgit log –follow [file]
Lists version history for a file, including renamesgit log –pretty=format:"%h %s" –graph
Pretty commit view, you can customize it as much as you wantgit log –author='Name' –after={1.week.ago} –pretty=oneline
abbrev-commit
See what the author has worked on in the last week
git log –no-merges master..
See only changes in this branchgit diff [file-branch]…[second-branch]
Shows content differences between two branchesgit show [commit]
Outputs metadata and content changes of the specified commit
Redo commits
git reset
Unstage pending changes, the changes will still remain on file systemgit reset [commit/tag]
Undoes all commits after [commit], preserving changes locallygit reset –hard [commit]
Discards all history and changes back to the specified commit
Synchronize changes
git fetch [bookmark]
Downloads all history from the repository bookmarkgit fetch -p
Update history of remote branches, you can fetch and purgegit merge [bookmark]/[branch]
Combines bookmark’s branch into current local branchgit push
Push current branch to remote branchgit push [remote] [branch]
Manually specify remote and branch to use every timegit push -u origin master
If a remote branch is not set up as an upstream, you can make it sogit pull
Downloads bookmark history and incorporates changesgit pull [remote] [branch]
Specify to pull a specific branchgit remote
See list of remote repos availablegit remote -v
Detailed view of remote repos availablegit remote add [remote] [url]
Add a new remote