How to set git bash default directory?

Git Bash is a command-line interface and terminal emulator for Git, providing a Unix-like environment on Windows to interact with Git version control and execute shell commands (bash Shell).

Set the default directory (method 1)

  • Decide which Windows folder to set as the 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 copied in the previous step.
 echo "cd 'C:\Users\admin\Desktop\my-git'" >> ~/.bash_profile
  • Ensure 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. From now on, gitbash will open your pre-defined directory upon opening it.
  • The 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 can now cd to your pre-defined project folder with the alias of your choice.
  • The picture below shows the alias creation step
gitbash aliases to project folders

More examples for gitbash cd aliases

Similarly, you may set any number of aliases for different folders(directories). Make sure to choose unique aliases for different destination directories, two 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