174

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
joseph.hainline
  • 24,829
  • 18
  • 53
  • 70

3 Answers3

338

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
joseph.hainline
  • 24,829
  • 18
  • 53
  • 70
  • 2
    Find more details (and examples) in the manual here: https://git-scm.com/book/en/v2/Git-Basics-Git-Aliases – Chris Oct 06 '21 at 18:20
20

Also, can edit this into your git config:

[alias]
   co = checkout
isomorphismes
  • 8,233
  • 9
  • 59
  • 70
sma
  • 9,449
  • 8
  • 51
  • 80
  • 3
    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. – John Szakmeister Jan 23 '13 at 23:11
  • 6
    for people who don't know where is git config: vi ~/.gitconfig or git config --global -e – fangzhzh May 20 '14 at 02:00
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.

ccjli
  • 103
  • 1
  • 8