How to set Git Bash directory to home? - bash

when I start up git bash I get the following location as my startup location:
[Me]#[Me] MINGW64 /
$ dir
bin cmd dev etc git-bash.exe git-cmd.exe LICENSE.txt mingw64 proc
ReleaseNotes.html tmp unins000.dat unins000.exe usr
How can I change it so that I am in my documents folder on my computer?

As in all versions of bash, this is the default behavior of cd if given no arguments, or the explicitly-specified behavior of cd ~ or cd "$HOME":
$ pwd
/
$ cd
$ pwd
/c/Users/Charles Duffy
Similarly, cd ~/Documents will move to the Documents subdirectory of same.

If you set the Windows environment variable %HOME% to your Document folder, a simple cd will get you there.
set HOME=%USERPROFILE%\Documents
git bash
cd
With git version 2.8.3.windows.1, typing git bash in any folder opens a git bash in that folder.
Then type cd and you are at $HOME.

There are side effects of setting HOME. For example emacs gets a new home, which is not in the roaming profile.
So, as an alternative, edit .bash_profile, add this at the end: cd ~ .

Related

Git Bash: My Desktop folder not found help me

$ cd /Desktop
bash: cd: /Desktop: No such file or directory
and start. command finally I have got the Desktop folder
You can try :
$ cd ~/Desktop
where ~ represents your home directory.
If you are using git bash it does not matter which os you use, your home directory located at ~ and Desktop is under ~/Desktop
Windows
Under windows, it will be mapped to /c/Users/<your user>/Desktop
Linux based Os
Under unix/linux it will be your /home//Desktop

problems with git bash on windows. i can't access folders on git bash for windows

i bought a course from codecademy and at beginner was a lesson about git bash. I install it , but if i want to change directories with "cd" i cant't.
enter image description here
Also , when i double-click on shortcut the program doesn't run.
Try changing to you home directory first
$ cd
then
$ pwd
/c/Users/yourname
Try going to you root directory with : cd / (make sure you add a space between cd and /)
Then do cd yourfilename/yourfilename....you can add multiple directories
Make sure your spelling is correct
Few other tips :
To navigate to your home directory use "cd ~".
To navigate to the previous directory use "cd -"

Change directory in bash script in windows

How can I change my working directory in bash script in windows. I have
~dp0 = C:\test\docker\windows and I want to change my directory to C:\test\build
So it means 2 levels up and then int o build folder
Thanks
Since C:\ is mounted by default into /mnt/c this will work.
Create a .bashrc in your home path by following command:
echo "BUILDDIR=/mnt/c/test/build" >> ~/.bashrc;source ~/.bashrc
cd $BUILDDIR
# Do your work below for example ./configure.
./configure
On my system in Git bash the C:\ root is just /c/ and other dirs from there are whatever they are, so it would be cd /c/test/build/.
You could also still say cd ../../build/.
Good luck.
To change the directory using a bash script is just like you would using normal bash.
cd "C:/test/build"
echo "You're now in the folder, do what you will."
Save the file as .sh and it can be used as such.
Note, when navigation your folders using a bash script remember the directory you'll be starting from is always the home directory.

How do I reverse the cd command in the Terminal on Mac OS X?

I am beginning to learn ruby and was following the instructions of one video to access the desktop through the -ls command in the terminal. Now, I would like to get out of the desktop in the terminal and don't know how. I know, I know I am a total noob... but can someone please help. Thanks. BTW the command I wrote was:
my-iMac~ me$ cd Desktop/
my-iMac:Desktop samuel$ ls
Where would you like to go?
Go home: cd or cd ~
Go to the previous working directory: cd $OLDPWD
Go to parent of the current directory: cd ..
Go to any directory you want: cd /path/to/directory
cd .. will take you back up 1 level.
for windows, you can open up the file explorer copy path then in your command prompt type "cd" then paste path. Your command prompt should now default to that path. (you can also type the entire path)
cd C:\Users\username\Documents\Folder

Switching to an aliased directory

Just wanted to know if it is possible to switch to an aliased directory using shell script.
To switch to a directory there is cd command. But i have aliased the directory and wanted to know as how to switch to the aliased directory.
Could someone please help me?
An alias is meant to be a shortcut for a command.
You can't cd to an aliased directory.
But if you have a variable referencing that directory, you can. e.g.
dev="/path/to/my/dev"
cd $dev
Or set up an alias to cd to the directory:
alias dev='cd /path/to/my/dev'

Resources