The Basics git init#Create a Git repository in the current folder. git status#View the status of each file in a repository. git add #Stage a file for the next commit. git commit#Commit the staged files with a descriptive message. git log#View a repository’s commit history. git config --global user.name ""#Define the author name to be used in all repositories. git config --global user.email #Define the author email to be used in all repositories. Undoing Changes git checkout #View a previous commit. git tag -a -m ""#Create an annotated tag pointing to the most recent commit. git revert #Undo the specified commit by applying a new commit. git reset --hard#Reset tracked files to match the most recent commit. git clean -f#Remove untracked files. git reset --hard / git clean -f#Permanently undo uncommitted changes. Branches I git branch#List all branches. git branch #Create a new branch using the current working directory as its base. git checkout #Make the working directory and the HEAD match the specified branch. git merge #Merge a branch into the checked-out branch. Branches II git commit -a -m ""#Stage all tracked files and commit the snapshot using the specified message. git branch -D #Force the removal of an unmerged branch (be careful: it will be lost forever). Rebasing git rebase #Move the current branch’s commits to the tip of , which can be either a branch name or a commit ID. git rebase -i #Perform an interactive rebase and select actions for each commit. git commit --amend#Add staged changes to the most recent commit instead of creating a new one. git rebase --continue#Continue a rebase after amending a commit. git rebase --abort#Abandon the current interactive rebase and return the repository to its former state. git merge --no-ff #Force a merge commit even if Git could do a fast-forward merge. Rewriting History git reflog#Display the local, chronological history of a repository. git reset --mixed HEAD~#Move the HEAD backward commits, but don’t change the working directory. git reset --hard HEAD~#Move the HEAD backward commits, and change the working directory to match. git log ..#Display the commits reachable from but not from . These parameters can be either commit ID’s or branch names. git log --stat#Include extra information about altered files in the log output. Remotes git clone #Create a copy of a remote Git repository. git remote#List remote repositories. git remote add #Add a remote repository. git fetch #Download remote branch information, but do not merge anything. git merge /#Merge a remote branch into the checked-out branch. git branch -r#List remote branches. git push #Push a local branch to another repository. git push #Push a tag to another repository. Centralized/Distributed Workflows git init --bare #Create a Git repository, but omit the working directory. git remote rm #Remove the specified remote from your bookmarked connections. git remote rm #Remove the specified remote from your bookmarked connections. Patch Workflows git format-patch #Create a patch for each commit contained in the current branch but not in . You can also specify a commit ID instead of . git am < #Apply a patch to the current branch. Tips & Tricks git archive --format=zip --output=#Export a single snapshot to a ZIP archive called . git bundle create #Export an entire branch, complete with history, to the specified file. git clone repo.bundle -b #Re-create a project from a bundled repository and checkout . git stash#Temporarily stash changes to create a clean working directory. git stash apply#Re-apply stashed changes to the working directory. git diff ..#View the difference between two commits. git diff#View the difference between the working directory and the staging area. git diff --cached#View the difference between the staging area and the most recent commit. git reset HEAD #Unstage a file, but don’t alter the working directory or move the current branch. git checkout #Revert an individual file to match the specified commit without switching branches. git config --global alias. #Create a shortcut for a command and store it in the global configuration file. Plumbing git cat-file #Display the specified object, where is one of commit, tree, blob, or tag. git cat-file -t #Output the type of the specified object. git ls-tree #Display a pretty version of the specified tree object. git gc#Perform a garbage collection on the object database. git update-index [--add] #Stage the specified file, using the optional --add flag to denote a new untracked file. git write-tree#Generate a tree from the index and store it in the object database. Returns the ID of the new tree object. git commit-tree -p #Create a new commit object from the given tree object and parent commit. Returns the ID of the new commit object.