Created
December 7, 2015 21:17
-
-
Save dreamingechoes/3fe075f4ab6d3d5e786c to your computer and use it in GitHub Desktop.
Git cheat sheet.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
git init | |
# initializes an empty git in the current directory | |
git config -l | |
git config --global user.name "<your name>" | |
git config --global user.email "<your email>" | |
git config --global color.status auto | |
git config --global color.diff auto | |
git config --global color.branch auto | |
git clone <git host>:/repo/<projectName> | |
# copy a git repository so you can add to it | |
git add <file1 file2> | |
# adds files to the staging area | |
git add . | |
# recursively add all files under current directory | |
git add * | |
# add all files in current directory only | |
git checkout -- <file> | |
# reverts back the modified file to the one in the repository | |
git status | |
# view the status of your files in the working directory and staging area | |
git status -s | |
# short form. Left column for staging area. Right column for working dir | |
git diff | |
# show diff of unstaged changes | |
git diff --cached | |
# show diff of staged changes | |
git diff HEAD | |
# show diff of all staged or unstaged changes | |
git commit | |
# records a snapshot of the staging area | |
git commit -a | |
# stage modified files before commit. Does not add new files, but removes deleted files from staging area | |
git commit -m 'commit message goes here' | |
git commit --amend | |
# Update the last commit message | |
git commit --amend --reset-author | |
# Use this if you have changed your user name or email with git config and want to fix this identity for previous commit | |
git reset --hard HEAD | |
# This will throw away any changes you may have added to the git index and as well as any outstanding changes you have in your working tree. | |
git reset HEAD | |
# unstage all changes that were staged. Reset staging area to HEAD | |
git reset HEAD -- <file1 file2> | |
# unstage files. Reset the file to its snapshot in HEAD | |
git revert HEAD | |
# This will create a new commit which undoes the change in HEAD (i.e. the last commit). You will need to enter the message for the new commit. | |
git revert HEAD^ | |
# Git will attempt to undo the old change while leaving intact any changes made since then. | |
git rm <file1 file2> | |
# remove files from staging area and working dir | |
git rm --cached <files> | |
# remove files from staging area only | |
git rm -r subdir/ | |
# path = * to recursively remove subdirectories from staging area and working dir | |
git pull | |
git branch -a | |
git branch <branchName> | |
# create new local branch at your last commit. So all commits of current branch will be copied over to the new branch. | |
git push origin <branchName> | |
# push a new local branch to the server. If you do not explicitly push your new local branches, they stay in your repo and are invisible to others | |
git pull origin <branchName> | |
# pull a remote branch | |
git branch -d <branchName> | |
# delete branch. This command ensures that the changes in the branch (to be deleted) are already in the current branch. | |
git branch -D <branchName> | |
# delete branch. This command will NOT check if the changes in the branch (to be deleted) are already in the current branch. | |
git push origin :<branchName> | |
# will delete the branch on the origin remote | |
git branch --track <master> <origin/master> | |
#Add release branch?? | |
git checkout <branchName> | |
# Switch the branch you are currently on | |
git remote | |
git remote show <origin> | |
# Lists the URL for the remote repository as well as the tracking branch information | |
git log <release> | |
git log --name-status | |
git log -p | |
git log --pretty=full | |
git log --no-merges | |
# Ignore merges | |
git tag -l | |
# list tag names | |
git tag -a v1.4 -m 'version 1.4' | |
# Create tag with annotation | |
git tag v1.4 | |
# Create tag without annotation | |
git push --tags | |
# Push tags to remote | |
git show <tagname> | |
# Show tag and tagger details | |
#To rename a tag: | |
git tag NEW OLD | |
# First create NEW as an alias of OLD | |
git tag -d OLD | |
# Delete OLD | |
git push origin :OLD | |
# Delete OLD in remote branch | |
git stash | |
git stash apply | |
git stash list | |
git log stash@{2} | |
git show stash@{32} | |
git reflog | |
git reflog expire --expire=30.days refs/stash |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment