This brief tutorial describes how to change directories using Git Bash for beginners. Since I am fairly new to using the command line, using tools such as npm, Node.js, and Git Bash, I figured I would describe how I figured out to change directories, when starting a new project and initializing a Git repository. While I have used version control tools such as GUI’s – GitHub for Windows, Tortoise SVN for several years, learning the command line can be pretty intimidating and confusing, so providing an easy to understand way to get started being comfortable changing directories on your machine is the goal of this article.
This guide assumes that you already have Git installed on your machine and covers a basic installation using Windows 7. This guide also assumes that you have installed Git in the default directory as set in the installation process. On Windows 7, the default directory is C:\Program Files\Git. To install Git for Windows, click on this link.
Open Git Bash in your Windows Start menu. Once open you will see the following, an empty window with a dollar sign and a flashing cursor:
From here you can type “dir” or “ls”. “ls” is a command to list files in Unix and Unix-like operating systems. Using “dir” will list the files as shown below:
Using “ls” will list the files as shown below:
By default, as shown above Git will list the files in your C:\Users\%user-profile%. You will notice that your folders are color coded. The light blue folders with the @ symbol, are folders that the current Windows account does not have access to. Folders with access are colored dark blue, with files having no color.
The first time I worked with Git Bash, I thought the command $ cd / would bring me back to the root folder, the C: drive. However, typing this in will bring you to the folder where Git is installed, C:\Program Files\Git, which is not what we may want.
My new repository is located in C:\Users\%user-profile%\Documents\Git\.git. To get here, we need to type in the following $cd /c/users/&user-profile%/documents/git, as shown below.
You will know you are now in a Git repository, evidenced by the (master) label after the path name in command prompt. Since this is a new repository, there are no files in my directory, so typing “ls” will show no results.
That’s it! Just an easy to follow guide for those of you who may need to find your way when dealing with a Unix command line for the first time. Enjoy!