How do I modify my Git Bash profile in Windows?

Solution 1:

When you open up your Git Bash, you should be in your home directory by default. Now create the .bashrc file (if on Windows 7 the file should be named .bashrc.).

If you're not in the home directory, change into it by typing:

cd

and pressing Enter. cd, without any other parameters listed after, will always return the home directory.

You can create the file by typing:

touch .bashrc

Then edit it with Vim or you could try doing it with some Windows editor, but I don't recommend it, because of some text formatting issues.

vim .bashrc

Change to Insert Mode by hitting the i key.

Add your alias by typing:

alias gs='git status'

Exit the insert mode by hitting the Esc key.

Save and close your file by typing the following :wqEnter.

:wEnter will only save your file.

:q!Enter will quit the editor without saving your file.

Finally, update the file to use your new changes by typing:

source .bashrc

Solution 2:

You can put .bash_profile in your user directory: C:\Users\<username>.

You can also create some git-only aliases so you can do just git st for git status by adding these lines to C:\Users\<username>\.gitconfig:

[alias]
st = status

Some other useful aliases:

cm = commit -m
cma = commit -a -m
br = branch
co = checkout
df = diff
ls = ls-files
sh = stash
sha = stash apply
shp = stash pop
shl = stash list
mg = merge
ph = push -u

Solution 3:

My git version is git version 2.18.0.windows.1 It took me a while to figure out where the .bashrc was C:\Program Files\Git\etc ---> bash.bashrc hope it helps

Solution 4:

If you can't find your ~/.bashrc file, you can add all aliases to your ~/.bash_profile file.

For instance, to add an alias for a Git command (git status) simply add:

alias gs="git status"

In the same way you can add an alias for a Bash command (change directory path):

alias myd="cd ~/path to my directory"

Solution 5:

Simply (if you have .bashrc you will add aliases to the end of file):

cat >> ~/.bashrc

Paste or type a list of aliases. Press Ctrl + D and finally run:

source ~/.bashrc