How to change folder with git bash?

ぐ巨炮叔叔 提交于 2019-11-29 18:35:48

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 right click.Select 'Git bash' option.Git bash terminal automatically opens with the intended directory.For your example go to your project folder.while in the folder,right click and select the option and Git bash opens automatically with /c/project.

Steps that I follow

1) check in bash in which directory you are in by using command --> $ pwd

2) copy the URL of the directory to which you want to change the directory like after using my first command i.e PWD I got

--> $ /c/Users/yourUsername

3) Now I want to change this to the directory of c drive and folder MyPictures what I will do is I will go the directory of MyPictures and copy the URL and paste it in the git bash

**BUT Before that **

C:\MyPicture becomes this in bash --> $ cd /C/MyPicture

just backward slash becomes forward slash

Also

4) if the folder name is having some SPACES like (my program) then You need to enclose them in double quotes

--> $ cd "C:\Program Files"

5) If you have read so far then remember, to change directory you just need to copy the requiredUrl and paste that in bash with double-quotes that's it

cd "required URL"

Note: Required URL with front slashes :-)

Tanaka Tsoka

pwd: to check where you are (If necessary)

cd: change directory

In your case if I understand you, you need:

cd c/project

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 single quotes:

cd 'C:\project'

Or 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

Lanquo

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 your favorite folder.

Hope this might be useful.

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

  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 :)

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

user3734456

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

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

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.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!