How to set git bash default directory?

Set the default directory (method 1)

  • Decide which windows folder you want to set as gitbash default directory, and copy the complete directory path.
  • For example, suppose the location is : C:\Users\admin\Desktop\my-git
  • Open Gitbash and enter this command, replace the path with the path you have copied in the previous step.
 echo "cd 'C:\Users\admin\Desktop\my-git'" >> ~/.bash_profile
  • Make sure that you are placing the directory path between those two single-quotes.
  • We are setting the bash_profile, which tells the bash shell to cd to this directory when the shell opens up.
  • Close gitbash and open it again. This is a permanent change. Next time onwards, gitbash will open your pre-defined directory up on opening it.
  • Same steps are shown in the picture below.
gitbash set the default directory

With this, whenever you open Git Bash, the command line bash terminal will automatically open up your pre-set directory (Windows folder)

Create a bash aliases for changing directories (method 2)

With this method, you can pre-define aliases to change directories, such as project1 or project2. For example below, I have used cd-mydir as an alias.

  • Decide which windows folder you want to set the alias
  • For example (again) : C:\Users\admin\Desktop\my-git
  • Open Gitbash and enter this command, replace the path with the path you have copied.
  echo "alias cd-mydir=\"cd 'C:\Users\admin\Desktop\my-git'\"" >> ~/.bash_profile
  • Make sure that you are placing the directory path between those two single-quotes.
  • We are setting the bash_profile, which tells the bash shell to cd to this directory when we run the alias command cd-mydir.
  • Close gitbash and open it again.
  • You will be able to cd to your pre-defined project folder now with the alias of your choise.
  • Picture below shows the alias creation step
gitbash aliases to project folders

More examples for gitbash cd aliases

Similar way, you may set any number of aliases for different folders(directories). Make sure to choose unique aliases for different destination directories, 2 more examples are below with aliases named: code and tryout.


 echo "alias code=\"cd 'C:\Users\admin\Documents\github\project-code'\"" >> ~/.bash_profile

 echo "alias tryout=\"cd 'C:\Users\admin\Documents\github\project-tryout'\"" >> ~/.bash_profile