<<
Home , Git

Git Cheat Sheet

GIT BASICS REWRITING GIT HISTORY

Create empty Git repo in specified directory. Run with no Replace the last with the staged changes and last commit git init git commit arguments to initialize the current directory as a git repository. combined. Use with nothing staged to edit the last commit’s message. --amend

Clone repo located at onto local machine. Original repo can be Rebase the current branch onto . can be a commit ID, git clone located on the local filesystem or on a remote machine via or . git rebase HTTP SSH branch name, a tag, or a relative reference to HEAD.

Define author name to be used for all commits in current repo. Devs git config Show a log of changes to the local repository’s HEAD. commonly use flag to set config options for current user. git reflog Add flag to show date info or to show all refs. user.name --global --relative-date --all git add Stage all changes in for the next commit. GIT BRANCHES Replace with a to change a specific file.

Commit the staged snapshot, but instead of launching git commit -m List all of the branches in your repo. Add a argument to a text editor, use as the commit message. git branch "" create a new branch with the name .

git checkout -b Create and check out a new branch named . git status List which files are staged, unstaged, and untracked. Drop the -b flag to checkout an existing branch.

Display the entire commit history using the default format. into the current branch. git log For customization see additional options. git merge

Show unstaged changes between your index and git working directory. REMOTE REPOSITORIES

Create a new connection to a remote repo. After adding a remote, git remote add you can use as a shortcut for in other commands. UNDOING CHANGES

Create new commit that undoes all of the changes made in git revert git fetch Fetches a specific , from the repo. Leave off , then apply it to the current branch. to fetch all remote refs.

Fetch the specified remote’s copy of current branch and Remove from the staging area, but leave the working directory git reset unchanged. This unstages a file without overwriting any changes. git pull immediately merge it into the local copy.

Shows which files would be removed from working directory. git push Push the branch to , along with necessary commits and git clean -n Use the flag in place of the flag to execute the clean. -f -n objects. Creates named branch in the remote repo if it doesn’t exist.

Visit .com/git for more information, training, and tutorials Additional Options +

GIT CONFIG GIT DIFF

Show difference between working directory and last commit. git diff HEAD git config --global Define the author name to be used for all commits by the current user. user.name git diff --cached Show difference between staged changes and last commit git config --global Define the author email to be used for all commits by the current user. GIT RESET user.email Reset staging area to match most recent commit, git config --global Create shortcut for a Git command. E.g. .glog “log --graph git reset alias. but leave the working directory unchanged. --oneline” will set ”git glog” equivalent to ”git log --graph --oneline. Reset staging area and working directory to match most recent Set text editor used by commands for all users on the machine. git config --system git reset --hard commit and overwrites all changes in the working directory. arg should be the command that launches the desired editor (e.g., vi). core.editor

Move the current branch tip backward to , reset the git config Open the global configuration file in a text editor for manual editing. git reset staging area to match, but leave the working directory alone. --global --edit Same as previous, but resets both the staging area & working directory to git reset --hard match. Deletes uncommitted changes, and all commits after GIT LOG .

Limit number of commits by . git log - E.g. ”git log -5” will limit to 5 commits. GIT REBASE

Condense each commit to a single line. git log --oneline git rebase -i Interactively rebase current branch onto . Launches editor to enter Display the full diff of each commit. commands for how each commit will be transferred to the new base. git log -p

Include which files were altered and the relative number of git log --stat lines that were added or deleted from each of them. GIT PULL

Fetch the remote’s copy of current branch and rebases it into the local git log --author= Search for commits by a particular author. git pull --rebase copy. Uses git rebase instead of merge to integrate the branches. ” git log Search for commits with a commit message that --grep=”” matches . GIT PUSH git log Show commits that occur between and . Args can be a git push Forces the git push even if it results in a non-fast-forward merge. Do not use .. commit ID, branch name, HEAD, or any other kind of revision reference. --force the --force flag unless you’re absolutely sure you know what you’re doing.

git push Push all of your local branches to the specified remote. git log -- Only display commits that have the specified file. --all

Tags aren’t automatically pushed when you push a branch or use the git log --graph --graph flag draws a text based graph of commits on left side of commit git push flag. The flag sends all of your local tags to the remote repo. --decorate msgs. --decorate adds names of branches or tags of commits shown. --tags --all --tags

Visit atlassian.com/git for more information, training, and tutorials