This is a collection of scripts and aliases that I use regularly whilst working with Git.
- Clone this repo somewhere e.g.
~/git-tools
- Source the
activate.sh
file in your shell init script e.g..zshrc
or.bashrc
For example, on my machines I run something like this:
git clone https://github.com/Drarok/git-tools.git ~/git-tools
echo 'source "~/git-tools/activate.sh"' >> ~/.zshrc
By default, git-tools will set up some short aliases which you can see in aliases-default.sh
. You can replace
these with your own by creating a file named aliases.sh
in the git-tools
directory. Note that aliases.sh
will
take precedence over aliases-default.sh
so be sure to copy over any aliases you want to keep.
Lists (and optionally removes) branches that have been merged to "safe" branches – develop and master by default.
develop $ git dead-branch
feature/new-buttons
fix/something-cool
develop $ git dead-branch --cleanup
Deleted branch feature/new-buttons (was 2dd9a39).
Deleted branch fix/something-cool (was a3a5173).
If you are merging many features to a long-lived branch, you can specify that branch as "safe":
develop $ git dead-branch
There are no dead branches.
develop $ git dead-branch version-2
Deleted branch feature/v2-major-stuff (was 12abda1).
Deleted branch fix/v2-bug-fixes (was b347334).
It also supports checking (but not removing) remote branches.
develop $ git dead-branch -a
remotes/origin/feature/something-merged
If you are on a branch that has been merged upstream (such as when you still have your just-merged Pull Request branch checked out), you can use this to tidy up. Think of is as saying "The current branch has been merged to <branch>".
It switches to the destination branch (develop by default), does a pull
, then deletes the branch you were on.
Finally, it also performs a prune on the remote, keeping the list of remote branches in sync with upstream.
feature/new-buttons $ git merged
f628724..93a5b00 develop -> origin/develop
Deleted branch feature/new-buttons (was 2dd9a39).
develop $
hotfix/emergency-kittens $ git merged master
a5b8751..36c5316 master -> origin/master
Deleted branch hotfix/emergency-kittens (was 6adb76d).
master $
This one is extremely lazy. When you have a new branch you want to push, you have to specify its name, and set a flag if you want to track it. No longer! This tool is a lazy person's git push -u $remote $current_branch
.
feature/brand-new-awesome $ git publish
Publishing feature/brand-new-awesome to origin.
Branch feature/brand-new-awesome set up to track remote branch feature/brand-new-awesome from origin.
feature/optional-remote-name $ git publish github
Publishing feature/optional-remote-name to github.
Branch feature/optional-remote-name set up to track remote branch feature/optional-remote-name from github.
Simple management for different name/email combinations e.g. home and work.
develop $ git profile --add work --name 'Random Developer' --email '[email protected]'
develop $ git profile --add home --name 'G. R. R. Developer' --email '[email protected]'
develop $ git profile home
Switched to profile home: G. R. R. Developer <[email protected]>
develop $ git profile
work (Random Developer <[email protected]>)
* home (G. R. R. Developer <[email protected]>)