如何在 Windows 上更改 Git Bash 的默认位置?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7671461/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 12:00:48  来源:igfitidea点击:

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

gitwindows-7git-bash

提问by Alex Waters

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?

我在 Windows 7 上使用 Git 并通过 Git Bash 访问我的存储库。当我启动 Git Bash 时,如何更改它在方便的文件夹中打开的默认位置?

It's somewhat time consuming to navigate to htdocs, and then a specific folder. Is there a way to change the configuration file to have it open elsewhere? Or would it be possible to write a .shfile to do this?

导航到htdocs,然后导航到特定文件夹有点耗时。有没有办法更改配置文件以使其在其他地方打开?或者是否可以编写一个.sh文件来执行此操作?

Unfortunately Git Bash won't open my htdocsfolder shortcut on my desktop, and it takes using cd5 times to get to my desired directory.

不幸的是,Git Bash 不会htdocs在我的桌面上打开我的文件夹快捷方式,它需要使用cd5 次才能到达我想要的目录。

采纳答案by Marcin Gil

After installing msysgit I have the Git Bash hereoption in the context menu in Windows Explorer. So I just simply navigate to the directory and then open Bash right there.

安装 msysgit 后,我Git Bash here在 Windows 资源管理器的上下文菜单中有该选项。所以我只是简单地导航到目录,然后在那里打开 Bash。

I also copied the default Git Bashshortcut to the desktop and edited its Start inproperty to point to my project directory. It works flawlessly.

我还将默认Git Bash快捷方式复制到桌面并编辑其Start in属性以指向我的项目目录。它完美无缺。

Windows 7x64, msysgit.

Windows 7x64,msysgit。

回答by Mohammad Arif

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

不安装 msysgit 的最简单方法是右键单击 Git Bash 快捷方式图标→开始于:→“C:\Program Files (x86)”。

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

更改Start in条目并指出 Git Bash 的起始位置。如果您不--cd-to-home从“目标”框中删除该部件,则更改中的开始将被覆盖。

回答by soundswaste

Add this line to your .bashrcfile:

将此行添加到您的.bashrc文件中:

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\

如果 .bashrc 文件不存在,请在您的根文件夹中创建一个。对我来说是:C:\Users\tapas\

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

保存 .bashrc 并打开 Git Bash。就是这样!

回答by Vladimir Despotovic

Open the properties of the bash and change to "Start in" to where you want to start in. After this, (I had this problem and I solved it by doing this) go to target and delete the --cd-to-home parameter part after "C:\Program Files\Git\git-bash.exe" . Only THEN will you start in the "Start in" directory that you specified.

打开 bash 的属性并更改为“Start in”到您想要开始的位置。在此之后,(我遇到了这个问题并通过这样做解决了它)转到目标并删除 --cd-to-home "C:\Program Files\Git\git-bash.exe" 之后的参数部分。只有 THEN 才会在您指定的“Start in”目录中开始。

回答by Chinmoy

I read it somewhere and it worked for me.

我在某个地方读过它,它对我有用。

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

首先检查 git bash 什么是 HOME 位置。打开 git bash 并运行

echo $HOME

Now change the HOME path by opening cmd and run

现在通过打开 cmd 并运行来更改 HOME 路径

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

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

现在通过在 git bash 中运行 echo 命令来交叉检查。

回答by Groostav

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 Bashicon, select properties, and change the Start in:field.

如果你像我一样,进入 Git 的方式是windows key+ G+ I+ Enter,那么你可以简单地点击windows key,搜索 Git,右键单击结果Git Bash图标,选择属性,然后更改Start in:字段。

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.

我不确定这是做什么的,因为我不确定 Windows 上的 Git 是什么(sh 顶部的外观,它本身是 cmd 的外观?),但无论如何,您现在可以固定快捷方式Windows 会在你的任务栏或桌面上搜索“Git”,它仍然会在你设置的任何目录中启动。

回答by Professor Chaos

Windows 10 tested solution

经过 Windows 10 测试的解决方案

  • Type git bash in search

  • Right click on it and choose open file location

  • Right click on it and choose properties

  • At targetremove --cd-to-homefrom "C:\Program Files\Git\git-bash.exe" --cd-to-home

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

  • 搜索中输入git bash

  • 右键单击它并选择打开文件位置

  • 右键单击它并选择属性

  • 目标删除--cd到户从“C:\ Program Files文件\的Git \混帐bash.exe” --cd到户

  • 开始时输入您希望它开始的目录的路径,例如开始:C:\xampp\htdocs

回答by smilyface

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

Git bash 用于玩 bash 命令。所以我在 Windows 中使用 bash 方法本身Git bash

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

编辑您的.bash_profile(如果您没有,请创建它 - 请参阅下文如何创建)。输入以下几行。

Add these lines to the file

将这些行添加到文件中

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

My .bash_profile looks like this

我的 .bash_profile 看起来像这样

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

How to create a new .bash_profile ?

如何创建一个新的 .bash_profile ?

touch ~/.bash_profile

OR write into the file directly

或者直接写入文件

vi ~/.bash_profile 

Simple, aha !

很简单啊哈!

回答by Icementhols

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

更新Start in:字段后,请确保删除字段--cd-to-home末尾的Target:

回答by Anant Singh

Right click on Git Bash shortcutand then go to properties.
In propertiesinside start inoption add the location of the directory you want to start Git Bashin and applythe changes.

右键单击Git Bash shortcut,然后转到properties
propertiesinsidestart in选项中添加要启动的目录的位置Git Bashapply更改。