I am developing on a windows machine. The only place I need for linux command line is Git Bash. The problem is: When I open it, I am in the home directory. I have to change the directory to my workspace, like:
cd ../../../d/work_space_for_my_company/project/code_source
Can I wrap this in a .sh file so I don't have to hand-type it anymore? This should be simple but I have zero knowledge about Linux command line. I am really appreciated If you can walk me through how to create that .sh file.
For windows: Follow these steps-
cd-to-home
from target
(b) Type folder path you want to start with git in "Start in".This worked for me:)
it must be cd d:/work_space_for_....
without the :
it doesn't work for me
If you want to have projects choice list when u open GIT bash:
ppath
in code header to your git projects path, put this code into .bashrc file and copy it into your $HOME dir (in Win Vista / 7 it is usually c:\Users\$YOU)#!/bin/bash
ppath="/d/-projects/-github"
cd $ppath
unset PROJECTS
PROJECTS+=(".")
i=0
echo
echo -e "projects:\n-------------"
for f in *
do
if [ -d "$f" ]
then
PROJECTS+=("$f")
echo -e $((++i)) "- \e[1m$f\e[0m"
fi
done
if [ ${#PROJECTS[@]} -gt 1 ]
then
echo -ne "\nchoose project: "
read proj
case "$proj" in
[0-`expr ${#PROJECTS[@]} - 1`]) cd "${PROJECTS[proj]}" ;;
*) echo " wrong choice" ;;
esac
else
echo "there is no projects"
fi
unset PROJECTS
My Git Bash shortcut on Windows complained when I put the cd to my work directory into ~/.bashrc
WARNING: Found ~/.bashrc but no ~/.bash_profile, ~/.bash_login or ~/.profile.
This looks like an incorrect setup.
A ~/.bash_profile that loads ~/.bashrc will be created for you.
So git created this .bash_profile:
$ cat ~/.bash_profile
# generated by Git for Windows
test -f ~/.profile && . ~/.profile
test -f ~/.bashrc && . ~/.bashrc
Which does the job.
Alternatively, you can just remove the .bashrc again and put the cd command into .bash_profile:
$ rm ~/.bashrc
$ echo "cd Source/Repos" >~/.bash_profile
$ cat ~/.bash_profile
cd Source/Repos
Once this is done you can close the Window and re-open it using your desktop shortcut and the prompt will tell you that your location is now where you wanted it - looks like this is my case:
Administrator@raptor1 MINGW64 ~/Source/Repos
$
This may help you.
--go-to-home
or it will continue to start in the directory specified in your HOME variableThats it.
Here's a more Windows-ish solution: Right click on the Windows shortcut that you use to launch git bash, and click Properties. Change the value of "Start In" to your desired workspace path.
Edit: Also check that the Target value does not include the --cd-to-home option as noted in the comments below.
If you type this command:
echo cd d:/some/path >> ~/.bashrc
Appends the line cd d:/some/path
to .bashrc
. The >>
creates a file if it doesn’t exist and then appends.
I also just changed the "Start in" setting of the shortcut icon to: %HOMEDRIVE%/xampp/htdocs/
I use ConEmu (strongly recommended on Windows) where I have a task for starting Git Bash like
Note the button "Startup dir..." in the bottom. It adds a -new_console:d:<path>
to the startup command of the Git Bash. Make it point to wherever you like
Another solution for Windows users will be to copy the Git Bash.lnk file to the directory you need to start from and launch it from there.
Right-click the Git Bash application link go to Properties and modify the Start in location to be the location you want it to start from.
(Please read warning below)
Really simple way to do this in Windows (works with git bash, possibly others) is to create an environmental variable called HOME that points to your desired home directory.
NOTE: This may change the way other things work. For example, for me it changes where my .ssh config files live. In my case, I wanted my home to be U:\, because that's my main place that I put project work and application settings (i.e. it really is my "home" directory).
EDIT June 23, 2017: This answer continues to get occasional upvotes, and I want to warn people that although this may "work", I agree with @AnthonyRaymond that it's not recommended. This is more of a temporary fix or a fix if you don't care if other things break. Changing your home won't cause active damage (like deleting your hard drive) but it's likely to cause insidious annoyances later. When you do start to have annoying problems down the road, you probably won't remember this change... so you're likely to be scratching your head later on!
This will do it assuming you want this to happen each time you open the command line:
echo cd ../../../d/work_space_for_my_company/project/code_source >> ~/.bashrc
Now when you open the shell it will move up three directories from home and change to code_source.
This code simply appends the line "cd ../../../d/work_space_for_my_company/project/code_source" to a file named ".bashrc". The ">>" creates a file if it does not exist and then appends. The .bashrc file is useful for running commands at start-up/log-in time (i.e. loading modules etc.)
Add the line to the .bashrc
file in the home directory (create the file if it doesn't exist):
cd ~
touch .bashrc
echo "cd ~/Desktop/repos/" >> .bashrc
Source: Stackoverflow.com