A repository in computing is known as a central place in which data is stored and managed. So, a Git repository would mean a central location where all your project files will be stored and managed. Git repository is a folder inside your system where all your project files are located. It allows you to save versions of your code so that you can access them whenever needed. In your system, Git repository is a simple folder as many other folders.
Since, now we are very close to start doing Git activities, but we must know few Common Directory commands on Git Bash to make the process simple. These include
- Change directory using Git Bash
- Create a directory using Git Bash
- View all the directories in Git Bash
How to Change the Directory through Git Bash?
Changing the directory is important as you are always shuffling between different directories all the time while working with Git Bash. Directory is a technical term for folder. You can change the directory through two ways:
- Directly through Git Bash using commands
- By opening Git Bash in the desired folder
Browse to desired Directory through Commands in Git Bash
You can change the directory inside Git Bash with the help of cd command. cd command is commonly used in the shell of your system (cmd) for the same purpose. Here, I will change the directory to ToolsQA by cd command
1.Open your Git Bash.
2. Type the following command cd <path of the directory> and press enter. See that the directory has been changed.
Note: ToolsQA is a folder inside the E drive on my system.
Open Git Bash directly in the folder
Changing directory through opening it in the same folder is quite straight forward. For this, go to the directory to which you want to change the directory in a normal way you explore your system.
After this, right click anywhere in the directory => Open Git Bash here.
After we have learnt how to change the working directory, we can create a repository in any of the project folder where we need to work. For creating a repository, we will first create a folder in which we will work.
How to Create a New Directory using Git Bash?
Creating a directory using Git Bash is just a simple command which is used in Linux systems also. Although you can create the directory using the conventional method of creating a new folder but use Git Bash for as much work as possible. Let’s see how to create the directory using Git Bash.
1.Open Git Bash.
2. Navigate to directory in which you want to create a folder.
3. Type following command mkdir <folder name> and Press enter to create the directory.
Note: Remember that when you do not mention a more than one word directory name in quotes, it will create two directories namely First and Project. This we will see in the next section and then delete these folder and create a single directory called First Project.
How to View all the Directories in Git Bash?
Now that we have created the folder, we must also know how to look at all the directories/folders inside our working directory.
1.Navigate to the directory where you want to see the directories (ToolsQA)
2. Type the following command ls and press Enter. All the directories will be visible to you.
Note: It is worth noting that ls won’t show the hidden folders. You need to use ls -a for the same.
As we discussed in the above section, there are two directories created. We needed only one by the name of First Project. So for this use mkdir “First Project” command.
You can remove a directory by using rmdir command with the directory name.
Note: mk stands for Make and rm stands for Remove.
Now we are all set to initialize Git inside our project directory. As mentioned above, we need to know about the Git Init command for creating a repository. We will briefly see about the Git Init command in next tutorial.