Skip to content

Instantly share code, notes, and snippets.

@nnarain
Last active October 15, 2016 18:07
Show Gist options
  • Select an option

  • Save nnarain/5ce4cbe64d762a001f238a58d6882f96 to your computer and use it in GitHub Desktop.

Select an option

Save nnarain/5ce4cbe64d762a001f238a58d6882f96 to your computer and use it in GitHub Desktop.
Git cheatsheet

Git Cheat Sheet

Getting a remote branch without merging

git fetch origin my-branch

Aliasing Commands

Tired of typing out git command? Add an alias to make things easier.

git config --global alias.co checkout

This is one I normally use. I alias 'co' to checkout, so to checkout a branch I use:

git co my-feature

Rebasing

If multiple branches are being worked on in parallel it is necessary to keep git commit history up to date

If you are working on branch my-feature and changes were made to master you can update your commit history with git rebase

git checkout my-feature
git rebase master

When doing a rebase you can specify interactive mode to modify commit history.

git rebase -i master

Another way to squash commits

A really simple way to squash commits is to do a soft reset of your local branch with respect to another branch.

git checkout my-feature
git reset --soft master

Tagging

Annotated Tag

git tag -a 1.0.0 -m "v1.0.0"

Only push annotated tags

git push --follow-tags

Delete Tags

git tag -d release01
git push origin :refs/tags/release01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment