1

I find that every time I checkout a local branch, I do a git status. I want to add a git status to my alias for checkout to be more efficient.

I already have the following simple alias for checkout:

alias.co=checkout

I'd like to modify it so that no matter what arguments I provide to 'git co', it will always perform:

git co && git st

So for example, I could any of the following, and the alias should perform a git status afterwards:

git co -b newbranch
git co anotherbranch
git co -b andanother --track newbranch
git co -- "*.c"
4

2 回答 2

4

要在别名中运行多个 Git 命令,您需要修改别名以使用!,它运行 shell 命令,例如:

[alias]
    co = "!git checkout \"$@\" && git status"

应该将$@任何参数传播到git cothrough to git checkout

于 2014-06-25T14:39:01.770 回答
1

你可能最好为这样的事情编写一个 bash 脚本。就像是:

#!/bin/bash

if [[ $# == 0]]
then
    echo 'No branch name'
    exit 1
fi
git checkout "$*"
git status

然后,无论您将该文件保存为什么,都将是命令名称,然后第一个命令将是分支的名称。

于 2014-06-25T14:39:32.597 回答