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

后端 未结 18 944
暗喜
暗喜 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:03

    The working solution listed are great, but the problem occurs when you want multiple default home for your git-bash.

    A simple workaround is to start git-bash using bat script.

    git-bash-to-htdocs.bat

    cd C:\xampp\htdocs
    "C:\Program Files\Git\git-bash.exe" 
    

    The above of course assume git-bash is installed at C:\Program Files\Git\git-bash.exe

    You can create multiple .bat file so your git-bash can start where it want to be

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

    The easiest way without installing msysgit is right click on the Git Bash shortcut icon → Start in: → "C:\Program Files (x86)".

    Change the Start in entry and point out the Git Bash starting position. If you don't remove the --cd-to-home part from the Target box, the Start in change gets overridden.

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

    I read it somewhere and it worked for me.

    First check in git bash what is the HOME location. Open git bash and run

    echo $HOME
    

    Now change the HOME path by opening cmd and run

    setx HOME "path/to/.ssh/loc" (I gave C:\Users\aXXXX)
    

    Now cross check by running the echo command in git bash.

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

    Git bash is used to play with bash commands. So I use bash method itself in windows Git bash

    Edit your .bash_profile (create it if you doesnot have one - see below how to create). Enter the following lines.

    Add these lines to the file

    alias ws="cd /d/workspace/"
    ws
    

    My .bash_profile looks like this

    Smilyface@SmilingMachine /d/workspace
    $ cat ~/.bash_profile
    alias ws="cd /d/workspace/"
    ws
    

    How to create a new .bash_profile ?

    touch ~/.bash_profile
    

    OR write into the file directly

    vi ~/.bash_profile 
    

    Simple, aha !

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

    Once you have updated the Start in: field make sure to remove the --cd-to-home at the end of the Target: field

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

    Windows 10 tested solution

    • Type git bash in search

    • Right click on it and choose open file location

    • Right click on it and choose properties

    • At target remove --cd-to-home from "C:\Program Files\Git\git-bash.exe" --cd-to-home

    • At start in put the path of the directory you want it to start at for example Start in: C:\xampp\htdocs

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