1

I am learning how to use git bash for Windows and I want to start writing scripts to automate some of the git tasks I do. But where should I store the .sh files so that I can call them from any directory in git bash? Is there a standard directory they should be saved in?

At the minute I have to include a path to where the .sh file is. What I want is that when I am in git bash I can call the script just like I would any git command i.e. without a path.

3 Answers 3

1

You could edit your Path environment variable to include the folder to your scripts. Start --> Right click Computer --> Properties --> Advanced System Settings --> Environment Variables.

It is a System variable on Windows 7; separate each path with a semicolon.

After that, reload the command prompt and it should work.

0

You can run them from anywhere that the script has permissions to. I typically put my scripts in 'c:\scripts'.

0

Save it into the folder $HOME/bin.

If the script uses the extension .sh and you want to avoid typing the .sh everytime; you have a few options:

  1. Easy option is to add an alias in your $HOME/.bashrc like below

    alias mycmd='$HOME/mycmd.sh'
    
  2. Another option is to rename the file and just remove the .sh extension (not recommended) this could break some scripts depending on that command.

  3. Another option is to add a symbolic link.

    NOTE: You have to enable symbolic links during the installation.

    enter image description here

That's all.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .