Bootstrap FreeKB - Git (Version Control) - Version control in Git - Getting Started
Git (Version Control) - Version control in Git - Getting Started

Updated:   |  Git (Version Control) articles

Git is a version control system, where different versions of a file will be stored. First and foremost, you have to install Git on Windows or install Gi on Linux on the server that will be using Git.

 


Clone

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.

 


Branch

Branches are used as an isolated way to make changes to files in a repository. A common example would be to create a new branch using the git branch or git checkout command, switch to the new branch using the git checkout command, make a change to a file, commit the change using the git commit command, and then merge the branch to the master branch using the git merge command.

 


Log

Let's say there is a file named foo.txt in the repo. The git log command can be used to view the history of commits. In this example, every commit of foo.txt will be displayed.

git log foo.txt

 

The log will display entries like this.

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

 


Commit

Let's say there is a file named foo.txt in the repo, and you make a change to the file in your branch on your PC. You would then use the git commit command to create a new commit in your branch.

git commit foo.txt

 

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

 

Now, foo.txt in your branch on your PC will be different from foo.txt in the origin Git repository, because you have not yet pushed the commit from your branch to the origin Git repository.

 


Push

The git push command can now be used to push the updated commit from your branch to the origin Git repository. Now, foo.txt in your branch should be an exact match of foo.txt in the origin Git repository.

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 167ac8 in the box below so that we can be sure you are a human.