![](/base_images/jeremy.jpg)
The most basic way to use Git is to use the git clone command to clone an origin Git repository (such as example.git) to a directory on your PC (such as /home/john.doe/git), make a change to a file in the cloned repository on your PC (such as example.txt), use the git commit command to commit the change to the file, and to then use the git push command to upload the file to the origin Git repository.
Let's say you have cloned a Git repository and the git status command return No commits yets. This simply means you have cloned an empty repository that contains no files. In this scenario, you would use the git add command to add a file to the Git repository.
~]$ git status
On branch master
No commits yet
nothing to commit (create/copy files and use "git add" to track)
On the other hand, let's say there is a file named foo.txt in the currently selected branch of the cloned repository. The git ls-files command can be used to list the files that have been added to the currently selected branch of the cloned repository. In this example, foo.txt has been added.
~]# git ls-files
foo.txt
The git log command can be used to view the history of commits.
git log foo.txt
Notice in this example "third commitment" is the latest commit. HEAD is usually the latest commit in the currently selected branch.
commit mks910122020slsmm3lsosos020399489sl
Author: John Doe <john.doe@example.com>
Date: Wed May 31 14:51:14 2020 -0500
Third commitment
commit dkci85474fjfdkd9393934k49f9fk002kd01
Author: John Doe <john.doe@example.com>
Date: Tue May 30 18:23:36 2020 -0500
Second commitment
commit fj83m3ld0d0d3m3ld0389303l3ld0d0d39dl
Author: John Doe <john.doe@example.com>
Date: Mon May 29 20:26:09 2020 -0500
First commitment
Let's say you do not make any changes to foo.txt. In this example, the git status command returns nothing to commit, working directory clean since no changes have been made to foo.txt.
~]$ git status foo.txt
# On branch master
nothing to commit, working directory clean
Let's say you make a change to foo.txt. Now the git status command should return the following.
~]$ git status
# On branch 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: foo.txt
#
no changes added to commit (use "git add" and/or "git commit -a")
The git commit command is used to create a new commit. Your default editor will open, where you will be prompted to enter a commit message. Enter a message, and save.
git commit foo.txt
Better yet, the -m or --message option can be used to include the commit message on the command line.
git commit --message 'First Commitment' foo.txt
If the commit is successful, something like this should be displayed.
1 file changed, 1 insertion(+)
Reissuing the git log command should show the new commit.
commit 4f92bf5356b525b282db6af250eb927824663500
Author: John Doe <john.doe@example.com>
Date: Wed Jul 17 14:51:14 2020 -0500
Fourth commitment
commit mks910122020slsmm3lsosos020399489sl
Author: John Doe <john.doe@example.com>
Date: Wed May 31 14:51:14 2020 -0500
Third commitment
commit dkci85474fjfdkd9393934k49f9fk002kd01
Author: John Doe <john.doe@example.com>
Date: Tue May 30 18:23:36 2020 -0500
Second commitment
commit fj83m3ld0d0d3m3ld0389303l3ld0d0d39dl
Author: John Doe <john.doe@example.com>
Date: Mon May 29 20:26:09 2020 -0500
First commitment
And now the git status command should again return nothing to commit, working directory clean since your changes to foo.txt have been commited.
~]$ git status foo.txt
# On branch master
nothing to commit, working directory clean
Did you find this article helpful?
If so, consider buying me a coffee over at