If you are willing to be in “git-mode” all the time,
the simple answer is to put the following commands:
alias fetch='git fetch'
alias status='git status'
alias diff='git diff'
alias add='git add'
alias commit='git commit'
alias push='git push'
into your ~/.bashrc
.
But this may be undesirable,
if only because there is a regular command called diff
,
and you wouldn’t be able to access it
if diff
is aliased to git diff
1.
So the next, tiny, increase in complexity is to set it up
so that the aliases can be activated and deactivated dynamically.
You can do that with
alias enter-git-mode="alias fetch='git fetch'; alias status='git status'; alias diff='git diff'; alias add='git add'; alias commit='git commit'; alias push='git push'"
alias exit-git-mode="unalias fetch status diff add commit push"
So now enter-git-mode
is a command (alias)
that defines the first six aliases,
and exit-git-mode
is a command that undefines them.
You can split that long command into multiple lines if you want:
alias enter-git-mode="alias fetch='git fetch'; alias status='git status';
alias diff='git diff'; alias add='git add';
alias commit='git commit'; alias push='git push'"
alias exit-git-mode="unalias fetch status diff add commit push"
This allows you to use these commands just like any other command; e.g.,
date; status; date # A simple way of seeing how long a command takes.
time add .
commit &
commit && push
diff > differences.txt
and autocomplete,
and you can intermix regular Unix/Linux commands with git
commands —
except, of course, you can’t run diff
1.
Obviously, this does not magically handle all git
commands.
If you want to handle more subcommands (e.g., archive
or branch
),
you need to add them to the aliases.
________
1 except by typing /bin/diff
or /usr/bin/diff