banner



How To Change The Current Working Directory To Your Local Project In Git Bash

A folder is referred to as a directory. When working within Fustigate and utilizing the Git version control arrangement, changing the directory is crucial because you always travel betwixt several folders. There are two ways to change the directory:

  • Using commands straight in Git Bash
  • Git Bash is launched in the chosen folder.

Before using the alter directory command, nosotros must first ensure that git is installed on our Linux or some other UNIX-similar operating organization. To ostend this, we must check the git version; if the git version is displayed on the beat screen, information technology signifies that git is installed on our operating system. The command we used to check the git version is listed below; it is not necessary to run this control from the root or domicile directory:

Case 01: Check Current Working Directory

In this tutorial, we'll await at how to change the current working directory in git bash using bash Linux commands on Kali Linux. The cd command in Git Bash allows you to motility within the directories, probably from the electric current directory to some other directory. The control "cd" means "change directory." The cd control can be widely used in any Linux system's shells (cmd) for the same purpose. Before using the "cd" instruction, we need to find out the electric current working directory of our system using the "pwd" instruction as shown.

To begin, make a list of the folders and files in the current directory. Open up the Git repository in your local Fustigate organisation to get started. We used the "ls" control to see the list of all files and folders in the current directory in the screenshot. If we don't know the precise name of the directory or folders nosotros want to scan to, we can employ the ls command to run into all of the bachelor directories and files in the current directory. Every bit shown below, we take a unmarried folder of git named 'works' in our electric current working directory, and many files exist in this folder. Let'due south look at a few instances of how to motion among git directories using various commands.

Case 2: Change Git Directory

We'll change the current directory from "/home/Linux/" to the "works" folder in the case below. To navigate our desired destination directory, we have been utilizing the keyword "cd" in the command line followed by the directory'south name, i.e., works. This moves us within the "works" directory. Using the "ls" instruction, we learned that it contains a text file and a binder project1 in it. If we want to motion inside the project1 binder, we have to apply the aforementioned "cd" instruction as shown. While in the "project1" directory, nosotros accept used the "pwd" control to display the path of this current working directory.

$ cd works
$ ls
$ cd project 1
$ pwd

Example 3: Movement from Git Folder to Home Directory

The "cd" command can be used to motility dorsum toward your home directory again when yous are currently at another location, i.eastward., "works." If y'all're going direct to the dwelling house directory/folder, this command will come in handy. The first line reveals that we used the cd (change directory) control without specifying a directory name.

Example 4: Movement Back to Git Folder

To return to (or forwards to) the previous directory/folder, you can besides use the "cd -" instruction. If you accidentally browsed to the incorrect directory, this control will be very convenient to use. We were previously in the works directory, and so instead of typing the control with the whole path, nosotros used the (cd -) control to render to information technology. Following the execution of this command, the operating system brings united states of america to the works folder, as shown.

In a bureaucracy, the root directory is the first or topmost directory. If you're in another directory, type "cd /" to move into the root directory as shown.

Use "cd.." to go up one directory level. We're currently in the project1 directory and want to go to the home directory, as shown in the instance beneath. We're using i level college to navigate. When we used the first "cd.." control, we moved to the "works" directory, and when we used the second "cd.." command, we moved to the "home" directory.

Nosotros can travel numerous levels back using the "/" sign in the "cd" command after double dots, just like we used the simple "cd.." instruction to move dorsum. The levels we desire to move back are determined by the amount of dots (.) and forward slashes (/). Brand sure to double-check that the number of levels provided in our command is right.

Example five: Go straight to the Desired Directory

Simply input 'cd' at the instruction area along with the exact path to the directory to spring to the desired directory. Nosotros should use the path inside the quoted symbols, due east.g., "/home/Linux/works/project1". If no directory is detected, you may receive a directory not found error. Meet the example beneath for an illustration.

$ cd /home/Linux/works/project1
$ pwd

By using the cd command and the whole path of the directory, we can navigate directly to our habitation directory, which is "/dwelling house/Linux/" as per the output below.

Conclusion

In this article, we have learned what a directory is and how to switch from one git directory to another via bash commands. We looked at several ideas too equally a real-world example of how to put them into exercise. While operating any other Linux or UNIX-like operating organisation other than kali Linux, the change directory command is equally useful.

About the writer

Hullo Readers, I am Omar and I have been writing technical articles from last decade. You can cheque out my writing pieces.

Source: https://linuxhint.com/git-bash-change-directory/

Posted by: hectorrusequithe.blogspot.com

0 Response to "How To Change The Current Working Directory To Your Local Project In Git Bash"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel