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.
Navigating file directories¶
-
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 thec
directory.c/
Print current location¶
-
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/
.
- Type Git Bash into your Windows search.
- Right-click on Git Bash, and select Open File Location.
C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Git
- Right-click on Git Bash, and select Properties.
- Change the value under Start:
C:\git
- Remove the
--cd-to-home
part of the Target value. - 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...
BDM@usott-bdm MINGW64 /c/git $ git status fatal: Not a git repository (or any of the parent directories): .git