Skip to content

Instantly share code, notes, and snippets.

@ctokheim
Last active December 11, 2015 11:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save ctokheim/4596685 to your computer and use it in GitHub Desktop.
Save ctokheim/4596685 to your computer and use it in GitHub Desktop.
Git: tricks
# if get recieve.denyCurrentBranch error try to pull from
# the repository instead of pushing. Alternatively just
# switch to a tmp branch.
# Permanently going back to previous commit
git reset --hard 123abc
# undo adding a file to be staged for commit
git reset myfile
# Checkout a previous commit into a separate branch
# without a branch name it will be in a headless state
git checkout -b old-state 123abc
# set the remote URL
git remote set-url origin ssh://newhost.com/myproject.git
# add a local directory to push
git remote add local /my/dirs/
# Describes simple add/remove tags in Git
# Add a tag
git tag -a v1.0.0
git push origin --tags
# Delete a remote tag
git tag -d my_tag
git push origin :refs/tags/my_tag
# add all files to staging
git add .
# switch branch
git checkout mybranch
# create new branch
git checkout -b newbranch
# delete a branch
git branch -d badbranch
# list all branches
git branch
# change configuration for repo
git config --local user.name "UserName"
git config --local user.email "UserEmail"
# change global config
git config --global user.name "UserName"
git config --global user.email "UserEmail"
# clone a gist and then merge changes from a forked gist
git clone git@gist.github.com:2322786.git # clone some random gist
git remote add changes git://gist.github.com/2661995.git # register remote of a forked gist
git fetch changes # get those changes
git merge changes/master # merge them
git push # update the gist
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment