Git Cheatsheet
Configuration
Show configuration
git config --listShow repository configuration
git config --local --listShow global configuration
git config --global --listSetup: push the current branch and set the remote as upstream
git config --global --add --bool push.autoSetupRemote trueCreate
Clone an existing repository
git clone http://domain.com/user/repo.gitCreate a new local repository
git initLocal Changes
Changes in working directory
git statusChanges to tracked files
git diffAdd all current changes to the next commit
git add .Commit with message
git commit -m "message"Change last commit
git commit -a --amendWARNING
Don't amend published commits!
Search
Search text on all files in the directory
git grep "hello"Search commits that introduced a specific keyword
git log -S "keyword"Commit History
Show all commits, starting with newest
git logShow all commits, starting with newest (brief version)
git log --onelineShow changes over time for <file>
git log -p <file>Check out who change what and when in <file>
git blame <file>Branch & Tags
List all local branches
git branchList all local/remote branches
git branch -aList all remote branches
git branch -rSwithc HEAD branch
git checkout <branch>Create and switch new branch:
git checkout -b <branch>Create a new branch from an exiting branch and switch to new branch:
git checkout -b <new_branch> <existing_branch>Create a new branch based on your current HEAD:
git branch <new-branch>Force delete a local branch
git branch -D <branch>Apply specific commit from another branch:
git cherry-pick <commit hash>Mark HEAD with a tag:
git tag <tag-name>List all tags:
git tagUpdate & Publish
List all current configured remotes:
git remote -vShow information about a remote
git remote show <remote>Add new remote repository, named ≶remote>
git remote add <remote> <url>Remove a remote
git remote rm <remote>Download all changes and directly merge/integrate into HEAD
git remote pull <remote> <url>Get all changes from HEAD to local repository
git pull origin mainPublish local changes on a remote
git push <remote> <branch>Push your tags
git push --tagsBetter git config settings
Reference: How Core Git Developers Configure Git
