COMPLETE GIT (VERSION CONTROL SYSTEM)🛡

SaravananVijayamuthu
Frontend Weekly
Published in
10 min readAug 17, 2020
GIT developed by Linus Torvalds

What is GIT?

Git is a free, open-source distributed version control system. This maintains track of the tasks and files as they evolve with the support of multiple collaborators over time.

What is the version control system?

Copyright → ToolsQA

Version control is a system that tracks modifications to a file or collection of files over time such that different copies may be restored later. If a developer had some bugs in the new version, of his code he can switch back to the previous(old) version.

When multiple developers work on a single project, the changes made by a single developer may affect the code of another developer. So, to resolve all these kinds of problems git has branches where each developer works on an individual branch with their code and tests their code, at last, they can merge all branches. It’s awesome right!!😎

Git advantages

  • distributed development
  • changelog of every file
  • faster development
  • source code backups, useful to restore the old version of code, when new code fails
  • individual features for a single project
  • isolated environment for every change to our code
  • git works offline in our local machine

How to install Git?

Git supports common platforms like Windows, Linux, mac os

Installing git in Linux (ubuntu)

Update your Linux before installing git

Now, you can install git

after installation, you can check it through checking version of git [git — version].

Installing git in Windows

Check the official website of Git: https:/git-scm.com/downloads

Click the Download Button for Windows and allow the download to complete.

It’ll start downloading according to your computer either it maybe 32 or 64 bits. After downloading extract it and install it on your local machine.

Creating repositories in Git

There are two ways to build repositories:

Cloning(Separate topic)

Git commands

Cloning will be a separate topic.

Now, let’s use Git commands. To create a repository we can use git init command to initiate an empty git repo in our project directory it’ll create a .git file. has configurations such as tags, objects, and template files.

. Create your directory for your project

. Go to the project folder

. Git init command

after initializing the git repository user can work on the files and pushing to remote repositories like GitHub.

Making changes in Git

It’s one of the important features available in git, we can track the changes of file or changes of anything in our project before we do a commit.

Command to check the status

(git status)

Status of the new repo

Status of the repo with changes

I have created a new file in the project directory index.html

Status of the repo after commit

cmd: git commit -m “(commit message)

Git Clone

Git clone command clones a remote directory from GitHub and creates a new directory in your local machine.

Only Public repo can be cloned.

Shallow clone allows you to clone the specified number of commits the user needed.

Staging area in Git

Copyright → Lynda

It’s a stage before commit. In this stage, we can create partial commits, edit files, or modify files preparing of a commit is called the staging area.

git add .

The above command is used to update any modified and newly created files to the staged area, deleted files are not considered for the staging area.

git add -u

The above command is used to update any modified and deleted files to the staged area, newly created files are not considered for the staging area.

git add -A

The above command is used to update any kind of modified, deleted and newly created files to the staging area

Deleting files in Git

Copyright → Lynda

If the user needs to delete unnecessary files, the user can remove/delete that file from the working tree this will stop tracking changes for that file.

git rm — cached filename.txt” only deletes the file from repo whereas other above cmd will delete both in filesystem and index.

This cmd will help the user to delete/remove the only specified set of extension files. For example Files with the extension (.py )

Users can restore the deleted file from the previous history of their repo.

Git Ignore

Copyright → Perforce Software

.gitignore file is used to exclude files, folders, and type of file extension to be excluded in the staging area and in git commits.

For example, in node.js project, the user will be excluding node_modules because it contains a lot of external packages/modules. Even junk files created automatically due to extensions of IDE’s.

Open git ignore file

Note that the file name should be .gitignore and it should be created only o the root directory of your project.

I’m using type nul> because I am using the Windows machine. It can change according to the user machine say for LINUX it’s Touch. Even you can create it through creating a new file and name it as .gitignore

Tagging in Git

Illustration by Justyna Mieleszko

Tags are used to mark your code. Tags are like “Bookmark” in git pointing to a specific commit. Even we can say tags are versions of your code v1, v2, v2.2, Creating a tag requires one parameter: the name of the tag.

There are two types of tags

  • Annotated tags
  • Lightweight tags

Annotated tags

Annotated tags are useful when you release project publicly, annotated tags contain metadata like tag message, timestamp, author name, release notes, etc, these are useful for releasing your project publicly because visitors or other unknown user are able to know the actual details and time stamp of the tag, annotated tags always point to a tag object in the git object database.

Cmd to create an annotated tag

It creates a LOCAL tag on the current branch,but when you push your latest commit to the remote repository, git doesn’t push tags user needs to push tags separately by command.

Lightweight Tags

Lightweight tags are simple tags which will be used locally mostly, to create lightweight tags just don’t provide any additional parameters like -m,-a. The lightweight tag is just a named pointer to the commit.

Cmd to create lightweight tags

Cmd to push tags

How to tag like professional?😎

Our v1 tag seemed like a good idea at first but we’ll see v2, v3, v4, etc. in the future. Meanwhile, some bugs will occur so we’ll get v4-fixed, or maybe v4.1. At some point, it will be difficult to stick to things.🤦‍♂️

Copyright → CommitStrip

Semantic versioning can solve that problem. This is one of the popular standards, using a few simple rules. Each version is formatted as MAJOR, MINOR, PATCH and each part will change according to the rules below.

  1. MAJOR when breaking backward compatibility,
  2. MINOR when adding a new feature which doesn’t break compatibility,
  3. PATCH when fixing a bug without breaking compatibility

NOTE ⚠️

Tags cannot begin or end with /.

You cannot use the characters ^, *, or : inside tags

Branches in Git

Source → Mickaël Marquez

When the user creates their first repo by default the main branch will be the Master branch.

Branches are like separate lines of development within the same Project.

For example, You are developing a new feature or an update for your application, But this shouldn’t collapse your main repo(Master). So, you can create another branch for that part of the new code test the code once you confirm it’ll not affect the main code you can Merge both Master and new branch.

How to view branches in Git 🤔

We can use the git branch parameter through this parameter we can check merged, unmerged, local branches by providing specific parameters.

The current branch has an * (asterisk ) before its name in the git output.

How to merge branches in Git 🤔

As I said above you can merge all your branches into the main/master branch.

Git Revert

We can’t erase commits in the remote repository if any other users need them. revert is used to make a fresh commit without an existing commit that we don’t want to use.

Git Reset

Source → Emily Mills

When we need to go back to the previous commit we can use git reset. This cmd is used to move(HEAD), the latest commit of our working tree. We can reset files too🤪.

.git reset –hard is used to delete, completely .hard resets working tree and index. uncommitted changes and staged files will be lost, if we use –hard.

Here n indicates the number of commits to reset.

Rebasing in Git

Rebasing is completely different from the merging.

Rebase rewrites the whole git workflow. “.git rebase” command adds all your specified branch commits to the top current branch (*) commit these new commits will get added to the current branch and this will be in sequential order similar to the previous branch. After rebasing, the new commit Ids will be changed.

Git cherry-pick

Cherry-pick allows move commits from one branch to another. Cherry-picking is to rearrange the order of commits in a sustainable manner. It creates new commit with different commit id after the current commit (HEAD).

If anything is not clear or you want to point out something, please reach me

Like this article? Follow @saravanan.vijayamuthu on Instagram

--

--

SaravananVijayamuthu
Frontend Weekly

Ambivert. Webdev. Communicator. Internet guru. Coffee enthusiast. cynophile.