$ git config --list
$ git config --local --list
$ git config --global --list
$ git config --system --list
$ git config --global color.ui auto
$ git config --global core.editor vi
$ git init
$ git init <directory>
Clone (download) a repository that already exists on GitHub, including all of the files, branches, and commits:
$ git clone [url]
$ git status
$ git diff
$ git diff <file>
$ git add .
$ git add -p <file>
$ git commit -a
$ git commit
$ git commit -m 'message here'
$ git commit -am 'message here'
$ git commit --date="`date --date='n day ago'`" -am "<Commit Message Here>"
$ git commit -a --amend
$ git commit --amend --no-edit
$ git commit --amend --date="date"
$ git stash list
$ git stash
$ git checkout branch2
$ git stash pop
$ git stash apply
$ git stash apply stash@{stash_number}
$ git stash drop
$ git log
$ git log --oneline
$ git log --author="username"
$ git log -p <file>
$ git log --oneline <origin/master>..<remote/master> --left-right
$ git blame <file>
$ git reflog show
$ git reflog delete
$ git branch
$ git branch -a
$ git branch -r
$ git checkout <branch>
$ git checkout <branch> -- <filename>
$ git checkout -b <branch>
$ git checkout -b <new_branch> <existing_branch>
$ git checkout <commit-hash> -b <new_branch_name>
$ git branch <new-branch>
$ git branch --track <new-branch> <remote-branch>
$ git branch -d <branch>
$ git branch -m <new_branch_name>
You will lose unmerged changes!
$ git branch -D <branch>
$ git tag
$ git tag -n
$ git remote -v
$ git remote show <remote>
$ git remote add <remote> <url>
$ git remote rename <remote> <new_remote>
$ git remote rm <remote>
Note git remote rm does not delete the remote repository from the server. It simply removes the remote and its references from your local repository.
$ git fetch <remote>
Updates your current local working branch with all new commits from the corresponding remote branch on GitHub:
$ git pull
git pull
is a combination of git fetch
and git merge
$ git remote pull <remote> <url>
$ git pull origin master
$ git pull --rebase <remote> <branch>
$ git push remote <remote> <branch>
$ git push <remote> --delete <branch> (since Git v1.7.0)
$ git push --tags
$ git merge <branch>
git branch --merged master
$ git branch --merged master | grep -v '^\*' | xargs -n 1 git branch -d
Don't rebase published commit!
$ git rebase <branch>
$ git rebase --abort
$ git rebase --continue
CAUTION! Changing history can have nasty side effects. If you need to change commits that exist on GitHub (the remote), proceed with caution.
$ git reset --hard HEAD
$ git reset HEAD
$ git checkout HEAD <file>
$ git revert <commit>
$ git reset --hard <commit>
$ git reset --hard <remote/branch> e.g., upstream/master, origin/my-feature
$ git reset <commit>
$ git reset --keep <commit>
$ git rm -r --cached .
$ git add .
$ git commit -m "remove xyz file"