Monday 15 July 2019

git status: Show working tree status


You can check the status of git project by executing 'git status' command.

Step 1: Let’s clone below branch and experiment with ‘git status’ command.

Clone gitHelloWorld repository.
$git clone https://github.com/harikrishna553/gitHelloWorld.git
Cloning into 'gitHelloWorld'...
remote: Enumerating objects: 6, done.
remote: Counting objects: 100% (6/6), done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 6 (delta 0), reused 3 (delta 0), pack-reused 0
Unpacking objects: 100% (6/6), done.
$
$ls
gitHelloWorld


Step 2: Navigate to 'gitHelloWorld' repository and execute the command git status.
$cd gitHelloWorld/
$
$git status
On branch master
Your branch is up to date with 'origin/master'.

nothing to commit, working tree clean

As you see the output of 'git status' command, it is telling that, I am in
master branch and repository is uptp date with remote master branch.

Step 3: Update welcome.txt file

This repository contains two files README.md and welcome.txt.
$ls
README.md welcome.txt

Update welcome.txt file by adding some content to it.


Step 4: Execute the command 'git status'.
$git status
On branch master
Your branch is up to date with 'origin/master'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

 modified:   welcome.txt

no changes added to commit (use "git add" and/or "git commit -a")

As you see the output, it is clearly telling that 'welcome.txt' file is updated and changes are not staged yet.


Step 5: Add file contents to local repository index.
$git add welcome.txt 
$
$git status
On branch master
Your branch is up to date with 'origin/master'.

Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

 modified:   welcome.txt

As you see the output now, it is clear that welcome.txt is in staged state and changed need to be committed to the local repository.


Step 6: Commit the changes to local repository.
$git commit -m "Added welcome message to welcome.txt file"
[master fdf597b] Added welcome message to welcome.txt file
 1 file changed, 1 insertion(+)


Step 7: Execute ‘git status’ command.
$git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
  (use "git push" to publish your local commits)

nothing to commit, working tree clean

$git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
  (use "git push" to publish your local commits)

nothing to commit, working tree clean


As you see the output, my local branch is ahead of remote master branch by 1 commit. Let me push the changes to remote branch.
$git push origin HEAD
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 12 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 353 bytes | 353.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To https://github.com/harikrishna553/gitHelloWorld.git
   70d8ded..fdf597b  HEAD -> master


Reexecute the command 'git status'.
$git status
On branch master
Your branch is up to date with 'origin/master'.

nothing to commit, working tree clean


As you see the output, both remote and local branches are in sync now.


Previous                                                    Next                                                    Home

No comments:

Post a Comment