A summary of commonly used Git command-line instructions for quick reference.
Configuring user information, initializing, and cloning repositories.
Set your username
Set a name that is identifiable for credit when reviewing version history.
git config --global user.name "[firstname lastname]"Set your email Set an email address that will be associated with each history marker.
git config --global user.email "[valid-email]"Enable helpful colorization Set automatic command line coloring for Git for easy reviewing.
git config --global color.ui autoInitialize a new repository Initialize an existing directory as a Git repository.
git initClone a repository Retrieve an entire repository from a hosted location via URL.
git clone [url]Working with snapshots and the Git staging area.
Check status Show modified files in the working directory, staged for your next commit.
git statusStage a file
Add a file as it looks now to your next commit (stage). (Tip: use git add . to stage all changes).
git add [file]Unstage a file Unstage a file while retaining the changes in your working directory.
git reset [file]View unstaged changes Diff of what is changed but not staged.
git diffView staged changes Diff of what is staged but not yet committed.
git diff --stagedCommit changes Commit your staged content as a new commit snapshot.
git commit -m "[descriptive message]"Isolating work in branches, changing context, and integrating changes.
List branches
List your branches. A * will appear next to the currently active branch.
git branchCreate a branch Create a new branch at the current commit.
git branch [branch-name]Switch branches
Switch to another branch and check it out into your working directory. (Tip: git switch [branch-name] is a modern alternative).
git checkout [branch-name]Merge a branch Merge the specified branch's history into the current one.
git merge [branch]Retrieving updates from another repository and updating local repos.
Add a remote Add a Git URL as an alias.
git remote add [alias] [url]Fetch from remote Fetch down all the branches from that Git remote.
git fetch [alias]Merge a remote branch Merge a remote branch into your current branch to bring it up to date.
git merge [alias]/[branch]Push to remote Transmit local branch commits to the remote repository branch.
git push [alias] [branch]Pull from remote Fetch and merge any commits from the tracking remote branch.
git pullExamining logs, diffs, and object information.
View commit history Show the commit history for the currently active branch.
git logCompare branches (commits) Show the commits on branchA that are not on branchB.
git log branchB..branchAView file commit history Show the commits that changed a file, even across renames.
git log --follow [file]Compare branches (diff) Show the diff of what is in branchA that is not in branchB.
git diff branchB...branchAShow object details Show any object in Git in a human-readable format.
git show [SHA]Versioning file removes and path changes.
Delete a file Delete the file from the project and stage the removal for commit.
git rm [file]Move or rename a file Change an existing file path and stage the move.
git mv [existing-path] [new-path]Show moved files in logs Show all commit logs with indication of any paths that moved.
git log --stat -MTemporarily store modified, tracked files in order to change branches.
Stash changes Save modified and staged changes.
git stashList stashes List stack-order of stashed file changes.
git stash listPop a stash Write working from the top of the stash stack.
git stash popDrop a stash Discard the changes from the top of the stash stack.
git stash dropRewriting branches, updating commits, and clearing history.
Rebase a branch Apply any commits of the current branch ahead of the specified one.
git rebase [branch]Hard reset Clear staging area, rewrite working tree from specified commit. (Warning: This discards local changes!)
git reset --hard [commit]