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

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

 


Clone

The git clone command clones a repository from the source Git repo (typically called "origin") to a directory on your PC. For example, the foo.git and bar.git repositories could be cloned.

 


Branch

After cloning a repository, by default, you will have a branch called "master" on your PC. The git branch command with the --all flag can be used to show the branches.

 


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.

 



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




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




Comments

Web design by yours truely - me, myself, and I   |   jeremy.canfield@freekb.net   |