Git Tips and Tricks

Shaphil Mahmud
2 min readSep 2, 2019

Helpful Git hacks

A collection of Git tips and tricks curated from the internet. They came in handy in many situations for me and I hope you find them useful as well.

Update the local list of remote branches

To update the local list of remote branches run the following

git remote update origin --prune

Source — https://stackoverflow.com/a/36358502/5341284

Rename a Git branch in local

To rename a Git branch in the local copy of the repository, do this

git branch -m <oldname> <newname>

To rename the current branch

git branch -m <newname>

Source — https://stackoverflow.com/a/6591218/5341284

Pull from one, push to another

It is possible to pull from one repository and push to another. Just change the pushurl setting.

git remote set-url — push origin user@example.com:repo.git

Merge up to a specific Commit

Checkout to the branch that is behind the branch you want to merge commits from. Then,

git merge <commit-id>

Git status on all repositories in a folder

Go to the folder containing all the repositories you want status on and then run the following command

find . -maxdepth 1 -mindepth 1 -type d -exec sh -c ‘(echo {} && cd {} && git status && echo)’ \;

--

--

Shaphil Mahmud

Fullstack Software Engineer. Lover of the backend. Friends with the Frontend. https://shaphil.me