Git, push all local branches to origin
At work when we do bug fixes we always create a numbered branch matching our ticket number off of our current production code:
git checkout -b [ticket number here] production
This makes for incredibly simple merging and passing bug fixes around. I come across the issue a lot where I will have about 5 bug fix branches created locally and cannot remember which ones I have pushed to my origin (github) and which I haven’t. There is a command to view unpushed commited branches:
git log --branches --not --remotes --simplify-by-decoration --decorate --oneline
This ugly thing pretty much just parses the log for commits not in your remotes and dumps the result with one branch per line. What it doesn’t do is push these branches for me. Instead of trying to remember that all the time I decided today to just chain a few linux commands I do remember to make it a bit easier for myself:
git branch | grep [0-9] | xargs git push origin
This much shorter command just takes all of my number named branches and tries to push them. If they are already up to date, no biggie, git just returns a nice message telling me so. Branches that need updating on my origin get updated.
This little command only works when my HEAD is not currently on one of my numbered branches, otherwise the little “*” causes way more things than I want to push to my origin. There are, I’m sure, many ways to make this command better, but this simple form with its few prerequisites (not being on one of the branches being pushed) works out great for me.
Anyone else have some tricks for keeping your origin up to date?