[git] 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?

This question is related to git git-bash

The answer is


For the fastest way $ cd "project"


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


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.


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.


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.


Simply type cd then copy and paste the file path.

Example of changing directory:

example of changing directory


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". enter image description here


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:

     syntax changes in 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.


pwd: to check where you are (If necessary)

cd: change directory

In your case if I understand you, you need:

cd c/project

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\"

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


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' ".

pwd command in Linux

  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.

enter image description here

  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. Going to child directory

3b) Now to traverse back into the parent directory, we make use of cd .. command: Please check the Image below: enter image description here

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.

enter image description here

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

enter image description here

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.

enter image description here

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

enter image description here

And you are good to go: ENJOY :)


just right click on the desired folder and select git-bash Here option it will direct you to that folder and start working hope it will work.