'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
?
Solution 1:[1]
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..."
Solution 2:[2]
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
.
Solution 3:[3]
Here are the steps I followed:
In bash, check in which directory you are by using the command:
$ pwd
copy the URL of the directory you want to go like after using the first command (
PWD
) I got:$ /c/Users/yourUsername
Now I want to change this to the directory of
c
drive and folderMyPictures
. To do that, I will go the directory ofMyPictures
, copy the URL, and paste it in the Git bash. However, before that:C:\MyPicture
becomes$ cd /C/MyPicture
(backslashes are replaced with slashes)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"
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.
Solution 4:[4]
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 or spaces, 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)
- Right click
The
cd
command can be memorized as "change directory".
See also
- ss64 - Bash CD command
- Stack Overflow - Forward slash vs backward slash for file path in git bash
Solution 5:[5]
pwd
: to check where you are (If necessary)
cd
: change directory
In your case if I understand you, you need:
cd c/project
Solution 6:[6]
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' ".
- 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.
- 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 :)
Solution 7:[7]
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.
Solution 8:[8]
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
Solution 9:[9]
Simply type cd
then copy and paste the file path.
Example of changing directory:
Solution 10:[10]
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\"
Solution 11:[11]
For the fastest way $ cd "project"
Solution 12:[12]
cd c:/Users/username/Folder/SubFolder
Solution 13:[13]
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.
Solution 14:[14]
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.
Solution 15:[15]
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".
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow