I have a cleanup command that integrates with fzf. It pre selects every merged branch, so I can just hit return to delete them all. But it gives me the opportunity to deselect to preserve any branches if I want. It also prunes any remote branches
# remove merged branches (local and remote)
cleanup = "!git branch -vv | grep ': gone]' | awk '{print $1}' | fzf --multi --sync --bind start:select-all | xargs git branch -D; git remote prune origin;"
https://github.com/WickyNilliams/dotfiles/blob/c4154dd9b6980...I've got a few aliases that integrate with fzf like an interactive cherry pick (choose branch, choose 1 or more commits), or a branch selector with a preview panel showing commits to the side. Super useful
The article also mentions that master has changed to main mostly, but some places use develop and other names as their primary branch. For that reason I always use a git config variable to reference such branches. In my global git config it's main. Then I override where necessary in any repo's local config eg here's an update command that updates primary and rebases the current branch on top:
# switch to primary branch, pull, switch back, rebase
update = !"git switch ${1:-$(git config user.primaryBranch)}; git pull; git switch -; git rebase -;"
https://github.com/WickyNilliams/dotfiles/blob/c4154dd9b6980...
> For that reason I always use a git config variable to reference such branches. In my global git config it's main
What about using git's own `init.defaultBranch`?I mean, while useless in terms of `git init` because the repo's already init'd, this works:
And if you have `init.defaultBranch` set up already globally for `git init` then it all just worksHmm that might be nice actually. I like not conflating those two things, but as you say if the repo is already init'd then there's no chance it'll be used for the wrong purpose.
In any case the main thrust was just to avoid embeddings assumptions about branch names in your scripts :)
You can pull another branch without switching first:
You can also rebase directly on the remote branch
Nice. That'll make things a bit smoother. Changing branches often trips me up when I would later `git switch -`.
Likewise with the other way around, just switch pull with push.
I have always done `git pull origin main -r`