Total Pageviews

Friday 26 March 2021

如何更优雅地切换 Git 分支

 在日常开发中,我们经常需要在不同的 Git 分支之间来回切换,特别是业务需求比较多的开发人员。在分支较多的情况下,分支名的 tab 自动补全会比较糟糕,切换时我们不免需要复制或手打分支名,那么有没有更优雅的方式了呢?

为了提高切换 Git 分支的效率,利用git-checkout-branch 这个小工具,可以交互式的切换分支,并自带搜索功能,帮助你更优雅的进行分支切换。

概览

Github 地址:https://github.com/royeo/git-checkout-branch 

说明:

  • 使用箭头键     进行移动,也支持 j 和 k 的上下移动
  • 使用 / 切换搜索
  • 按 ctrl + c 退出

安装

可以直接下载安装:

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

也可以使用 go get 安装,确保 $GOPATH/bin 路径在 PATH 中。

go get -u github.com/royeo/git-checkout-branch

建议为 checkout-branch 设置别名,例如 cb,这样就可以直接使用 git cb 来进行分支切换。

git config --global alias.cb checkout-branch

帮助

使用 git checkout-branch help 获取帮助信息。

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

---------------

Switch git branch interactively.

git-checkout-branch

CircleCI Go Report Card

The git-checkout-branch tool is a command-line tool for improving the efficiency of switching git branches. It is an extended git command.

Features

  • Switch git branch interactively
  • Search git branch dynamically

Overview

Instructions:

  • Use the arrow keys to navigate:    
  • You can also move up and down using j and k
  • Use / to toggle search
  • Press ctrl + c to quit

Installation

You can install the git-checkout-branch binary from GitHub Releases.

curl -sSL https://github.com/royeo/git-checkout-branch/releases/download/v0.4.0/git-checkout-branch-`uname -s`-`uname -m` -o /usr/local/bin/git-checkout-branch && chmod +x /usr/local/bin/git-checkout-branch

You can also use go get to install the git-checkout-branch binary:

go get -u github.com/royeo/git-checkout-branch

make sure the $GOPATH/bin folder is in your PATH.

It is recommended to set up an alias for checkout-branch, such as cb.

git config --global alias.cb checkout-branch

Usage

Use git checkout-branch help for 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
from https://github.com/royeo/git-checkout-branch

No comments:

Post a Comment