Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I avoid typing "git" at the begining of every Git command?

People also ask

How do I escape git?

Typing :wq and pressing enter should do it, i.e. save the commit message and exit. : enters the command mode, w is for "write" (save) and q is for "quit". You may need to hit escape before :wq to exit the insert mode ( vi is a mode based editor). If you want to exit without saving hit escape, :q! and enter.

Which comes first in git command?

The git init command creates a new Git repository. It can be used to convert an existing, unversioned project to a Git repository or initialize a new, empty repository. Most other Git commands are not available outside of an initialized repository, so this is usually the first command you'll run in a new project.


You might want to try gitsh. From their readme:

The gitsh program is an interactive shell for git. From within gitsh 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:

enter image description here

Or type git to get all the commands:

enter image description here


A friend of mine made a small bash script that accomplishes this. It's called Replify.

$ replify git
Initialized REPL for [git]
git> init
Initialized empty Git repository in /your/directory/here/.git/

git> remote add origin https://your-url/repo.git

git> checkout -b new-branch
Switched to a new branch 'new-branch'

git> push

Here is another way. It's also not quite what was asked, but I've been using it for some time and it is pretty nice. Add the following line to your ~/.bashrc:

complete -E -W git

Now pressing Tab at an empty Bash prompt will type out "git ".