QuickRef.
ME Search for cheatsheet ⌘K Sponsor Edit page
Git cheatsheet
This cheat sheet summarizes commonly used Git command line instructions for quick reference.
# Getting started
_ Create a Repository _ Make a change _ Configuration
Create a new local repository Show modified files in working directory, staged Set the name that will be attached to your
for your next commit commits and tags
$ git init [project name]
$ git status $ git config --global [Link] "name"
Clone a repository
Stages the file, ready for commit Set an email address that will be attached to your
$ git clone git_url commits and tags
$ git add [file]
$ git config --global [Link] "email"
Clone a repository into a specified directory
Stage all changed files, ready for commit
$ git clone git_url my_directory Enable some colorization of Git output
$ git add .
$ git config --global [Link] auto
Commit all staged files to versioned history
Edit the global configuration file in a text editor
$ git commit -m "commit message"
$ git config --global --edit
Commit all your tracked files to versioned history
_ Working with Branches _ Observe your Repository
$ git commit -am "commit message"
List all local branches Show the commit history for the currently active
Unstages file, keeping the file changes branch
$ git branch
$ git reset [file] $ git log
List all branches, local and remote
Revert everything to the last commit Show the commits on branchA that are not on
$ git branch -av branchB
$ git reset --hard
$ git log branchB..branchA
Switch to a branch, my_branch, and update
working directory Diff of what is changed but not staged
Show the commits that changed file, even across
$ git checkout my_branch renames
$ git diff
$ git log --follow [file]
Create a new branch called new_branch Diff of what is staged but not yet commited
$ git branch new_branch Show the diff of what is in branchA that is not in
$ git diff --staged
branchB
Delete the branch called my_branch Apply any commits of current branch ahead of $ git diff branchB...branchA
specified one
$ git branch -d my_branch
Show any object in Git in human-readable format
$ git rebase [branch]
Merge branchA into branchB
$ git show [SHA]
$ git checkout branchB
$ git merge branchA
Tag the current commit
$ git tag my_tag
_ Synchronize _ Remote _ Temporary Commits
Fetch down all the branches from that Git remote Add a git URL as an alias Save modified and staged changes
$ git fetch [alias] $ git remote add [alias] [url] $ git stash
Merge a remote branch into your current branch to Show the names of the remote repositories you've List stack-order of stashed file changes
bring it up to date set up
$ git stash list
$ git merge [alias]/[branch] $ git remote
Write working from top of stash stack
Transmit local branch commits to the remote Show the names and URLs of the remote
repository branch repositories $ git stash pop
$ git push [alias] [branch] $ git remote -v
Discard the changes from top of stash stack
Fetch and merge any commits from the tracking Remove a remote repository $ git stash drop
remote branch
$ git remote rm [remote repo name]
$ git pull
Change the URL of the git repo
Merge just one specific commit from another
branch to your current branch $ git remote set-url origin [git_url]
$ git cherry-pick [commit_id]
_ Tracking path Changes Ignoring Files
Delete the file from project and stage the removal /logs/*
for commit
!logs/.gitkeep
$ git rm [file]
/# Ignore Mac system files
.DS_store
Change an existing file path and stage the move
# Ignore node_modules folder
$ git mv [existing-path] [new-path]
node_modules
Show all commit logs with indication of any paths # Ignore SASS config files
that moved .sass-cache
$ git log --stat -M A .gitignore file specifies intentionally untracked
files that Git should ignore
# Git Tricks
Rename branch _ Log _ Branch
1 Renamed to new_name Search change by content List all branches and their upstreams
$ git branch -m <new_name> $ git log -S'<a term in the source>' $ git branch -vv
2 Push and reset
Show changes over time for specific file Quickly switch to the previous branch
$ git push origin -u <new_name>
$ git log -p <file_name> $ git checkout -
3 Delete remote branch
Print out a cool visualization of your log Get only remote branches
$ git push origin --delete <old>
$ git log --pretty=oneline --graph -- $ git branch -r
decorate --all
Checkout a single file from another branch
_ Commit Git Aliases
$ git checkout <branch> -- <file>
Rewrite last commit message git config --global [Link] checkout
git config --global [Link] branch
$ git commit -v --amend git config --global [Link] commit
git config --global [Link] status
See also: More Aliases
Top Cheatsheet Recent Cheatsheet
[Link]
Python Cheatsheet Vim Cheatsheet Neo4j Cheatsheet HTML Cheatsheet Share quick reference and cheat sheet for
developers.
Quick Reference Quick Reference Quick Reference Quick Reference
#Notes
Bash Cheatsheet JavaScript Cheatsheet GraphQL Cheatsheet Chmod Cheatsheet
Quick Reference Quick Reference Quick Reference Quick Reference
© 2021 [Link], All rights reserved.