TalkingQuickly's Today I Learned

2 posts about #git

A git remote can push to multiple repos

This is especially useful if you want to automatically push to master on github (for example) when doing git push heroku master to prevent you from ending up with the repo and your deployment being out of date.

It can be done like this (assuming you already have a Heroku branch setup):

git remote set-url --add --push heroku [email protected]:USERNAME/PROJECT.git
git remote set-url --add --push origin [email protected]:ccgmurdoch/my-project.git

And you can verify that it worked by taking a look at the output of:

git remote -v

Once this is done, a git push heroku master will automatically push the same branch to your github branch.


Removing local merged branches

In terminal, you can use:

git branch --merged | grep -v "\*" | grep -v master | grep -v develop | grep -v uat | xargs -n 1 git branch -d

To delete all local branches which have been merged, excluding in this case master, develop and uat. Great for quick cleanups.