In daily development, we often need to switch back and forth between different Git branches, especially for developers with more business needs. In the case of a large number of branches, the auto-completion of the branch name when switching branches is bad, we inevitably need to copy or manually type the branch name, so is there a more elegant way?
In order to improve the efficiency of switching Git branches, I used Golang to write a small tool called git-checkout-branch. It can switch branches interactively and has a search function to help you switch branches more gracefully.
An overview of
Github address: github.com/royeo/git-c… Welcome star.
Description:
- Use arrow keys
left
write
-
please
For mobile - use
j
和k
It can also move up and down - use
/
Switch the search - According to the
ctrl + c
exit
The installation
You can download and install it directly:
curl -sSL https://github.com/royeo/git-checkout-branch/releases/download/v0.2.0/git-checkout-branch- ` uname-s`-`uname -m` -o /usr/local/bin/git-checkout-branch && chmod +x /usr/local/bin/git-checkout-branch
Copy the code
You can also install using go Get, making sure the $GOPATH/bin PATH is in PATH.
go get -u github.com/royeo/git-checkout-branch
Copy the code
It is recommended to give checkout-branch an alias, such as cb, so that you can use Git cb directly for branch switching.
git config --global alias.cb checkout-branch
Copy the code
help
Use git checkout-branch help to get help information.
Checkout git branches more efficiently.
Usage:
git checkout-branch [flags]
Flags:
-a, --all List both remote-tracking branches and local branches
-r, --remotes List the remote-tracking branches
-n, --number Set the number of branches displayed in the list (default 10)
--hide-help Hide the help information
Copy the code