Git Tricks

Reset a branch to a previous commit

git reset --hard <old-commit-id>
git push -f

Get rid of old branches 

The command git remote prune origin --dry-run lists branches that can be deleted/pruned on your local. An option --dry-run is needed.

Fix slow and buggy repos

  • git gc (man page) runs a number of housekeeping tasks, such as compressing filerevisions (to reduce disk space and increase performance) and removing unreachable objects which may have been created from prior invocations of git add.
  • git repack (man page) re-organize existing packs into a single, more efficient pack.

Clone a git repo with limited history

Git’s shallow clone option allows you to pull down only the latest n commits of the repo’s history.

git clone --depth [depth] [remote-url]

example: git clone --depth 100 https://github.com/myaccount/myrepo.git

Post navigation

Leave a Reply

Your email address will not be published. Required fields are marked *