Skip to content

Instantly share code, notes, and snippets.

@jpinnix
Created February 18, 2019 22:07
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save jpinnix/1613088879f4726a354a8aefd9b8b1c8 to your computer and use it in GitHub Desktop.
git-cheat-sheet.md
command usage
git init Creates an empty Git repository in the specified directory.
git clone Clones a repository located at onto your local machine.
git add Stages only the specified changes for the next commit. Replace with a to change a specific file.
git add . Stages new files and modifications without deletions
git add -A Stages all changes
git add -all Equivalent to git add -A
git add -u Stages modifications and deletions without adding new files
git add --update Equivalent to git add -u
git commit -m ”” Commits the staged snapshot. replace with the commit message.
git status List which files are staged unstaged and untracked.
git log Displays the entire commit history using the default format.
git diff Shows unstaged changes between your index and working directory.
git pull Fetchs the remote copy of the current branch.
git pull --rebase Fetchs the remote copy of current branch and rebases it into the local copy. Use git rebase instead of merge to integrate the branches.
git push origin master Push all of your commits to master branch.
git push --all Push all of your local branches to the specified remote.
git push --tags Tags aren’t automatically pushed when you push a branch or use the --all flag. The --tags flag sends all of your local tags to the remote repo.
git push --force Forces the git push even if it results in a non-fast-forward merge. Do not use the --force flag unless you’re absolutely sure you know what you’re doing.
git revert Creates new commit that undoes all of the changes made in and then applys it to the current branch.
git reset Removes from the staging area but leaves the working directory unchanged - This unstages a file without overwriting any changes.
git clean -n Shows which files would be removed from working directory. Use the -f flag in place of the -n flag to execute the clean.
git commit --amend Replaces the last commit with the staged changes and last commit combined. Use with nothing staged to edit the last commit’s message.
git rebase Rebase the current branch onto . can be a commit ID a branch name a tag or a relative reference to HEAD.
git reflog Show a log of changes to the local repository’s HEAD. Add --relative-date flag to show date info or --all to show all refs.
git branch Lists all of the branches in your repo.
git branch Creates a new branch with the name .
git checkout -b Creates and check out a new branch named .
git checkout Checkout an existing branch.
git merge Merge into the current branch.
git remote add Creates a new connecti
git log --stat Include which files were altered and the relative number of lineson to a remote repo. After adding a remote you can use as a shortcut for in other commands.
git fetch Fetches a specific from the repo. Leave off to fetch all remote refs.
git pull Fetches the specified remote’s copy of current branch and immediately merge it into the local copy.
git push Pushes the branch to along with necessary commits and objects. Creates named branch in the remote repo if it doesn’t exist.
git config --global user.name Defines the author name to be used for all commits by the current user.
git config --global user.email Defines the author email to be used for all commits by the current user.
git config --global alias. Creates shortcut for a Git command. E.g. alias.p push will set git p equivalent to git push.
git config --system core.editor 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 --global --edit Opens the global configuration file in a text editor for manual editing.
git log - Limits the number of git rebase -i E.g. git log -5 will limit to 5 commits.
git log --oneline Condenses each commit to a single line.
git log -p Displays the full diff of each commit.
git log --stat Include which files were altered and the relative number of lines that were added or deleted from each of them.
git log --author= ”” Searchs for commits by a particular author.
git log --grep=”” Searchs for commits with a commit message that matches .
git log .. Shows commits that occur between and . Args can be a any kind of revision reference.
git log -- Only display commits that have the specified file.
git log --graph --decorate --graph flag draws a text based graph of commits on left side of commit msgs. --decorate adds names of branches or tags of commits shown.
git diff HEAD Shows difference between working directory and last commit.
git diff --cached Shows difference between staged changes and last commit
git reset Resets the staging area to match most recent commit but leaves the working directory unchanged.
git reset --hard Resets the staging area and working directory to match most recent commit and overwrites all changes in the working directory.
git reset Moves the current branch tip backward to resets the staging area to match but leaves the working directory unchanged.
git reset --hard Same as previous but resets both the staging area & working directory to match. Deletes uncommitted changes and all commits after .
git rebase -i Interactively rebase current branch onto . Launches editor to enter commands for how each commit will be transferred to the new base.

Original content from the csv file at: https://gist.github.com/BolajiAyodeji/d5393b90650c49ba9ef81493bfca9cda

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment