Working with the Command Line

If you don't have much experience using command-line, here are a couple of tips to help get you started.

  • To move between directories, you use the cd (change directory)command.

  • When you first open Git Bash, it opens in your home directory, which looks something like this:

    C:\Users\%LocalUser%
    
  • You can move up to a parent folder by entering ..

    For example,

    cd ../../
    

    cd tells the shell to change the directory and the ../../ says to move up two levels (parent of LocalUser, then parent of Users). Now you are in the c directory.

    c/
    
  • Use pwd to print your working directory (where you are).

  • List the contents of your current directory (the one you are in) by using ls.

    This command lists everything inside the folder.

  • Important commands for command-line navigation:

    command function
    cd change directory
    ls list items in current directory
    pwd show the path of my current location

Change the Git Bash default path

If you find it annoying to always have to cd ../../git/<project>, you can change the starting location of Git Bash so that you open Git Bash at git/.

  1. Type Git Bash into your Windows search.
  2. Right-click on Git Bash, and select Open File Location.
    C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Git
    
  3. Right-click on Git Bash, and select Properties.
  4. Change the value under Start:
    C:\git
    
  5. Remove the --cd-to-home part of the Target value.
  6. Click Apply.

When you open Git Bash, it should start in your Git directory.

Tip

After you change the starting path of Git Bash, pin it to your task bar.

Git with Git Bash

When you are in a git repository, you can run git commands.

For example, if you are in the help-documentation repo (which is currently checked out on the master branch),

BDM@usott-bdm MINGW64 /c/git/help-documentation (master)

you can run git commands by specifying git X, where X = the git operation.

git status
git branch
git --version
etc...
If you try to run git commands from a non-git directory, you get the following error:

BDM@usott-bdm MINGW64 /c/git
$ git status
fatal: Not a git repository (or any of the parent directories): .git