Create an empty Git repository
git init [my_project]Clone an external Git repository
git clone link.to.repository.gitList new or modified files not yet committed
git statusShow the changes to files not yet staged
git diffShow the changes to staged files
git diff --cachedShow all staged and unstaged file changes
git diff HEADShow the changes between two commit ids
git diff commit1 commit2List the change dates and authors for a file
git blame [file]Show the file changes for a commit id and/or file
git show [commit]:[file]Show full change history
git logShow change history for file/directory including diffs
git log -p [file/directory]List all the conflicted files
git diff --name-only --diff-filter=UShow all users and the number of commits on the repository
git shortlog --summary --numberedList all local branches
git branchList all branches, local and remote
git branch -avSwitch to a branch, my_branch, and update working directory
git checkout my_branchCreate a new branch called new_branch
git branch new_branchDelete the branch called my_branch
git branch -d my_branchMerge branch_a into branch_b
git checkout branch_b
git merge branch_aCheckout current branch into a new branch, named new_branch_name
git checkout -b new_branch_nameCreate branch new_branch based on branch other_branch and switch to it
git checkout -b new_branch other_branchTag the current commit
git tag my_tagTo fetch a branch
git fetch originCheckout the remote branch
git checkout -b test origin/testOr
git branch test origin/testStages the file, ready for commit
git add [file]Stage all changed files, ready for commit
git add .Commit all staged files to versioned history
git commit -m “commit message”Commit all your tracked files to versioned history
git commit -am “commit message”Adding more changes to the last commit
git commit --amendUnstages file, keeping the file changes
git reset [file]Delete last local commit, unstage files, keeping the changes
git reset --soft HEAD^Revert everything to the last commit
git reset --hardDiscard changes in working directory
git checkout -- <file>Checkout all project by revision number
git checkout revision_numberCheckout subdirectory by revision number
git checkout revision_number -- <subdirectory>Apply the changes introduced by some existing commits
git cherry-pick <commit-hash>Remove files from revision control
git rm --cached <file-path>To prevent git from detecting changes in these files
git update-index --assume-unchanged [path]Get the latest changes from origin (no merge)
git fetchFetch the latest changes from origin and merge
git pullFetch the latest changes from origin and rebase
git pull --rebasePush local changes to the origin
git pushPush to the current branch and set the remote as upstream
git push --set-upstream origin my_branchDefine the author name to be used for all commits by the current user.
git config --global user.name <name>Define the author email to be used for all commits by the current user.
git config --global user.email <email>Create shortcut for a Git command. E.g. alias.glog "log --graph --oneline" will set "git glog" equivalent to "git log --graph --oneline"
git config --global alias.<alias-name> <git-command>Set text editor used by commands for all users on the machine. arg should be the command that launches the desired editor (e.g., vi).
git config --system core.editor <editor>Open the global configuration file in a text editor for manual editing.
git config --global --editStore credentials indefinitely on disk for use by future Git programs
git config credential.helper storeList existing remotes
git remote -vChange remote's URL
git remote set-url origin https://new-remote-url.gitAdding a remote
git remote add origin https://new-remote-url.gitRenaming a remote
git remote rename origin destination