简体   繁体   中英

How to change folder with git bash?

My default git folder is C:\\Users\\username\\.git .

What command should I use to go into C:/project ?

The command is:

cd  /c/project/

Tip:
Use the pwd command to see which path you are currently in, handy when you did a right-click "Git Bash here..."

Go to the directory manually and do right click → Select 'Git bash' option.

Git bash terminal automatically opens with the intended directory. For example, go to your project folder. While in the folder, right click and select the option and 'Git bash'. It will open automatically with /c/project .

Here are the steps I followed:

  1. In bash, check in which directory you are by using the command:

     $ pwd
  2. copy the URL of the directory you want to go like after using the first command ( PWD ) I got:

     $ /c/Users/yourUsername
  3. Now I want to change this to the directory of c drive and folder MyPictures . To do that, I will go the directory of MyPictures , copy the URL, and paste it in the Git bash. However, before that:

    bash 中的语法更改

    C:\\MyPicture becomes $ cd /C/MyPicture (backslashes are replaced with slashes)

  4. if the folder name is having some spaces like (my program) then you need to enclose it in double quotes like:

     $ cd "C:\\Program Files"
  5. Remember to change directory you just need to copy the requiredUrl and paste that in bash with double-quotes like:

     cd "required URL"

Note: URL required with slashes.

How to change folders in Git Bash

As Bob mentioned , you can change directories with cd :

cd /c/project

If you have a Windows path with backslashes, enclose the path in double quotes:

cd "C:\project"

Tips

  • You can check the current folder with pwd .

  • If the path contains spaces, you will need to use quotation marks. ( cd "C:/Program Files" )

  • On Windows, you change the default starting directory for Git Bash.

    • Right click git-bash.exe , select Properties , open Shortcuts , and change Start in: to your most commonly used folder. ( screenshot )
  • The cd command can be memorized as " change directory ".

See also

pwd : to check where you are (If necessary)

cd : change directory

In your case if I understand you, you need:

cd c/project

Your Question is :

My default git folder is C:\\Users\\username.git

But I want to go into c:/project

What command do I need to get into that?

Since you have asked primarily about gitbash which is Linux based (Terminal), there are differences in commands when compared with Command Prompt of Windows. We'll discuss gitbash (Terminal) commands only.

1.First of all we must understand that command line(In Windows) and Terminal(In Mac) always points to some folder on storage Drives .

To check towards what directory it is pointing to at any given time. You need to type the command: pwd "an acronym for 'Print Working Directory' ".

Linux 中的 pwd 命令

  1. There is a command ls which gives us information about the folders and files in a particular directory. This is quite a handy command and often used to know about the file structure. In my answer I will make use of this also.

在此处输入图片说明

  1. To traverse along the folder tree we make use of yet another very important command know as cd which stands for change directory. And your question has the answer within this cd command only.

Here are some of the ways to traverse along the folder tree:

3a) cd command let's us traverse to child directory. Kindly check the snapshot. 转到子目录

3b) Now to traverse back into the parent directory, we make use of cd .. command: Please check the Image below: 在此处输入图片说明

By Using the above two steps we can easily solve your Query:

A) Currently you are in : C:\\Users\\username.git

So, doing cd .. will point the Terminal towards Users folder.

在此处输入图片说明

B) Again Typing cd .. will make Terminal to point towards C Drive.

在此处输入图片说明

C) Now doing ls at this point will let you know about all the folders and files in C drive.

Check if there is a project folder, Then simply for the last time type the command:

cd project

And Walla you are have traveled so far to reach to your destination. Congratulations.

在此处输入图片说明

Note: If the project folder is not created with C drive, simply write the command mkdir project and it will be created. Then follow the above steps to play around.

4) There is one more straight forward quick solution to your problem in particular:

Wherever the terminal is pointing. Simply write the command:

4a) cd / It will point to default root folder.

Then type the command : cd /c/ to point towards c directory. Then simply go to child directory, which in your case is project directory by typing:

cd project

在此处输入图片说明

And you are good to go: ENJOY :)

From my perspective, the fastest way to achieve what you're looking for is to change " Start in " value.

To do that, right-click on git-bash.exe , go to Properties and change Start In value to the folder you want.

Right clicking a specific folder can help ease your pain than just by typing the whole directory. Right click + clicking s or Right click and then click "GIT bash here"

Hope this seems helpful

Simply type cd then copy and paste the file path.

Example of changing directory:

更改目录的示例

I wanted to add that if you are using a shared drive, enclose the path in double quotes and keep the backslashes. This is what worked for me:

$cd /path/to/"\\\share\users\username\My Documents\mydirectory\"

最快的方式$ cd "project"

To move from c drive to other drive(D or E)use this command----->

cd "your path" Now hit enter. Check your path using $pwd. Your path has been change from one directory to other.

Ex---> cd "D:\\WEB_DEV\\HTML_CSS_projects\\TouristVisitors_LandingPage". note - this is my path, your path should be different.

cd c:/用户/用户名/文件夹/子文件夹

只需右键单击所需的文件夹并选择 git-bash Here 选项,它会将您定向到该文件夹​​并开始工作,希望它能正常工作。

if you are on windows then you can do a right click from the folder where you want to use git bash and select "GIT BASH HERE". 在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM