In this example, we are going to discuss Git Status. The Git status command shows the state of the working directory and the staging area. It allows you to see staged changes and the files that aren’t being tracked. The technology we will use here is Git bash. Open Git bash on your PC and let’s begin.
2. Git Status with working tree clean
The git status command is run from a newly
cloned repository in GitHub using the
git clone command followed by the link to the repository you want to clone which can be copied directly on your
github website. NB: You don’t need to add any argument after the git status command. Once you clone the repository and type the git status command, it triggers the following output.
The output released here can be interpreted as follows:
- On branch master: Tells you on which branch you are found.
- Your branch is up to date with ‘origin/master’: Meaning our local branch and remote branch commit history are synchronized.
- Working tree clean: There are no changes in the working directory proving that the working directory has the latest commit.
3. Git Status when a new file is created:
Assuming we create a new file inside our
cloned repository named
style2.css. We can use the
touch command to create a new file in
git. Next, we need to check the status of our repository using the git status command which will output the following:
The output here shows
"nothing is added to commit but untracked files present" (use "git add"
to track). According to the output, it is suggesting we do a
git add in order to track the new changes made. When we track the file using the
git add command as said and retype the
git status command, we get a different output as shown:
From the above output, we can see that the status after our file has been
staged by outputting
"Changes to be committed". It is important here to check the status every time before committing in order to avoid committing the changes we don’t want to commit. Let’s do a commit now and see the result as shown:
It is seen here that the current status after committing has been modified as clean again meaning that the
remote repository has
tracked the changes made on our
4. Git Status when an existing file is modified
In order to modify a file we use the
"echo" command. The command will add some text to the specified file. Next, we need to check the status of our repository with the git status command as shown:
This command will add some text as shown to the specified file which in our case is the
index.html file. Next, we can check the status of the repository by using the git status command as shown in the screenshot above. The output above shows us that the updated file is
untracked. The output in red shows us that it is not yet
staged once it will be, it will change from red to green as shown:
5. Git Status when a file is deleted
Assuming we want to delete the file we had created before named
style2.css from our repository. In order to delete an existing file, we use the:
$git rm <File Name> command. This command will delete a specific file from our local repository. After it is done, we now use the
git status command as such:
From the output above, the status of the repository has been modified as deleted.
In addition to describing the status of your
local branch, git status can also describe that of your
remote branch relative to the local one. In order to get an accurate result we have to use the
git fetch command first to ensure that our
local repository is aware of the latest changes made on the
remote repository. When collaborating with others on a
git, it is important to pay attention to the
status of your
repository. This information is useful to keep track of the
local commits that you can
push or those that need to be