Create a gist now

Instantly share code, notes, and snippets.

Gitisms - useful git invocations for everyday use.
# get the name of the currently checked out tag
git describe --tags --abbrev=0
# list all branches (local and remote)
git branch -a
# list all tags
git tag
# delete a tag
git tag -d tag-name
# create a tag and push to master
git tag tag-name
git push --tags
# make sure you have latest tags
# (because a git pull wont automatically do it for you)
git fetch --tags
# show a list of existing remotes
git remote
# checkout and fetch a branch
git checkout -b branch-name origin/branch-name
#
# sometimes the above will complain with:
#
# fatal: git checkout: updating paths is incompatible with switching branches/forcing
# Did you intend to checkout ‘origin/‘ which can not be resolved as commit?’
#
# it just means you need to do a `git pull` first.
#
# checkout and track a remote branch
git checkout -t /remotes/origin/branch-name
# checkout a tag (but first make sure you have the latest)
git fetch --tags
git checkout tag-name
# cherry pick a commit into another branch (the commit id will be the hash number printed after a commit - it looks something like: df76d32)
git checkout another-branch
git cherry-pick commit-hash
# revert a file (in the same sense as a revert in svn)
git checkout the-file-to-revert
# get git to keep an empty directory
touch /path/to/empty/dir/.gitkeep
git add /path/to/empty/dir
git commit -a -m '-- blah --'
git push
# create a new remote branch, fetch, switch and track locally
git push origin origin:refs/heads/new-branch-name # create the new remote branch
git fetch origin # makes sure everything is up-to-date
git branch -r # verify that the branch is created (visually)
git checkout --track -b v1.0.8 origin/new-branch-name # checkout and track the new branch locally
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment