I\'m wondering if there\'s a way to avoid having to type the word git
at the beginning of every Git command.
It would be nice if there was a way to use the
You might want to try gitsh. From their readme:
The
gitsh
program is an interactive shell for git. From withingitsh
you can issue any git command, even using your local aliases and configuration.
- Git commands tend to come in groups. Avoid typing
git
over and over and over by running them in a dedicated git shell:sh$ gitsh gitsh% status gitsh% add . gitsh% commit -m "Ship it!" gitsh% push gitsh% ctrl-d sh$
Or have a look at the other projects linked there:
- git-sh - A customised bash shell with a Git prompt, aliases, and completion.
- gitsh - A simple Git shell written in Perl.
- repl - Wraps any program with subcommands in a REPL.
Note: Haven't used this myself.
A Perl one-liner which will do this:
perl -nE 'BEGIN {print "git > "} system "git $_"; print "git > "'
This will execute whatever you type, prefixed with git
. And it will keep doing that until you hit ^D
.
This is not exactly what you're asking for, but you could set up some shell aliases in your ~/.bashrc
for the Git commands you use most frequently:
alias commit='git commit'
alias checkout='git checkout'
...
Also note that you can create aliases within Git itself:
git config --global alias.ci commit
git config --global alias.co checkout
...
This lets you type git ci
instead of git commit
, and so on.
I'm a big fan of using aliases in ~/.bash_profile for my GitBash. If you go with this approach, here are some of my favorites:
# git
alias gw='git whatchanged'
alias gg='git grep -n -C8'
alias ggi='git grep -i -n -C8'
alias gb='git branch'
alias gbd='git branch -D'
alias gba='git branch -a'
alias gc='git checkout'
alias gcp='git cherry-pick'
alias gfo='git fetch origin'
alias s='git status'
alias gmom='git merge origin/master'
alias grom='git rebase origin/master'
alias gpom='git pull origin master'
alias pplog='git log --oneline --graph --decorate'
Use your editor.
Type the command like commit
from your favorite editor like vs code and be more efficient with git:
Or type git
to get all the commands:
For basic stuff, you can do:
function ggit(){ while true; do printf 'git> '; read; eval git $REPLY; done }
git> status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
(use "git push" to publish your local commits)
Changes not staged for commit:
(use "git add/rm <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
deleted: yarn.lock
no changes added to commit (use "git add" and/or "git commit -a")
git> add .
git> status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
(use "git push" to publish your local commits)
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
deleted: yarn.lock
git>
Exit with ctrl+c