Skip to content

Instantly share code, notes, and snippets.

@nicolasramy
Last active December 14, 2015 11:39
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save nicolasramy/5081035 to your computer and use it in GitHub Desktop.
Save nicolasramy/5081035 to your computer and use it in GitHub Desktop.
Tips for git: manage remotes, branches, tags and history

Git Cheat Sheet

Remote

Add remote RemoteName from specific URL (SSH)

git remote add RemoteName git@git.hostname.com:repository.git

Get informations about the remote

git remote show origin

Delete remote branch

git push origin :BranchName

Fork

Sync a repository from another one

git remote add original_project git://github.com/repo/project.git
git fetch original_project
git checkout master
git merge original_project/master

Branch

Track distant branch

Git 1.8.0

git branch -u origin/branchName branchName
git branch --set-upstream-to=origin/branchName branchName

Git 1.7.0

git branch --set-upstream branchName origin/branchName

Checkout remote branch

git checkout -b banchName origin/banchName

Update remote branch list

git remote prune origin

Update remote branch list in Dry-run mode

git remote prune -n origin

Merge BranchA into BranchB

git checkout BranchB
git merge BranchA

Rename local branchA to branchB

git branch -m branchA branchB

Rename remote (origin) branchA to branchB

git push origin branchA:branchB

Delete local branch

git branch -D BranchName

Delete remote branch

git push origin :BranchName

Tags

List local tags

git tag

Tag a specific commit

git tag -a TAG_NAME SHA1_COMMIT

List remote tags

git-ls-remote --tags

List local tags with short description

git tag -n

Replace tag

git tag OLD_TAG_NAME NEW_TAG_NAME

Delete tag

git tag - d TAG_NAME

Sharing Tags

git push origin --tags
git pull origin --tags

Diff

Differences between 2 branches - detailed

git diff master..develop > diffs.log

Differences between 2 branches - summary

git diff --name-status master..develop > diffs-summary.log

Differences between 2 files

git diff master:file.php develop:file.php

History

View history

git log

View history as a tree

git log --graph --oneline --all

View history for a specific file

git log --follow -p file

View commit count per contributors

git shortlog -sne
@Geoffrey-T
Copy link

This can save my life ! Ty

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