How to alias 'git checkout' to 'git co'
Asked Answered
M

3

184

I'd like the command git co to be the same as typing git checkout.

A normal Bash alias (alias co='checkout') doesn't work.

Mesozoic answered 23/1, 2013 at 20:49 Comment(0)
M
349

The command:

git config --global alias.co checkout

will create a git alias to do that. It will add the following entry into your global ~/.gitconfig file:

[alias]
    co = checkout
Mesozoic answered 23/1, 2013 at 20:49 Comment(1)
Find more details (and examples) in the manual here: git-scm.com/book/en/v2/Git-Basics-Git-AliasesApplaud
K
22

Also, can edit this into your git config:

[alias]
   co = checkout
Key answered 23/1, 2013 at 21:17 Comment(2)
You don't need to do '!git'. You can just use 'co = checkout'. That prevents re-invoking git under another process... which can be advantageous on Windows where starting a new process is expensive.Alleluia
for people who don't know where is git config: vi ~/.gitconfig or git config --global -eDunant
C
0

simply to add some comments, the bash alias is for setting alias for a command, and the co or checkout is the parameter or flag to the command git, so it won't work.

Conall answered 12/12, 2019 at 21:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.