How do I change the default location for Git Bash on Windows?

后端 未结 18 945
暗喜
暗喜 2020-11-28 01:32

I am using Git on Windows 7 and access my repositories through Git Bash. How can I change the default location that Git Bash opens in a convenient folder when I start it?

相关标签:
18条回答
  • 2020-11-28 02:11

    If you're like me, and the way you get to Git is windows key + G + I + Enter, then you can simply hit the windows key, search for Git, right click on the resulting Git Bash icon, select properties, and change the Start in: field.

    I'm not exactly sure what this does, because I'm not exactly sure what Git on Windows is (a facade on top of sh which itself is a facade on cmd?), but in any case, you can now pin the shortcut that Windows pulls up on a search for "Git" to your taskbar, or to your desktop, and it will still start in whatever directory you set it to.

    0 讨论(0)
  • 2020-11-28 02:11

    I am using Git bash on Windows 10, here is my solution:

    1. Close all git bash sessions
    2. Hit windows key and type: env; then click Edit environment variables for your account (control panel)
    3. Under "User variables for ...."; hit New button
    4. Variable Name: HOME
    5. Variable value: path where you would like ~/ to be in git bash

    Open a git bash session and test it by typing: pwd and double check by doing cd ~/ && pwd

    0 讨论(0)
  • 2020-11-28 02:20

    I tried the following; it helped me. I hope it help you also.

    cd /c/xampp/your-project
    
    0 讨论(0)
  • 2020-11-28 02:21

    Add this line to your .bashrc file:

    cd C:/xampp/htdocs/<name of your project>;
    

    If the .bashrc file doesn't exist, create one in your root folder. For me it is: C:\Users\tapas\

    Save .bashrc and open Git Bash. That's it!

    0 讨论(0)
  • 2020-11-28 02:22

    Make a Git Bash shortcut to Desktop for convenience then right click on the icon goto properties. Here you will find the Start in: section with a text box. Replace the path you want, for example like:

    %USERPROFILE%\Desktop
    

    Then open it directly by clicking on the icon. You will get the default Desktop path in Git Bash.

    0 讨论(0)
  • 2020-11-28 02:24

    I liked Peter Mortenson's answer, but I would like to expand.

    'cd ~' in the .bashrc file causes the "Git Bash Here" feature of Git Bash to stop working. Instead, add this if statement to the .bashrc file:

    if [ "$PWD" == '/' ]
    then
            cd ~
    fi
    

    This will change to the home directory when Git Bash is run on its own, but when "Git Bash Here" is run, the current working directory will not be changed.

    0 讨论(0)
提交回复
热议问题