What is git?

What is git?

Are you a programmer? If yes, then you must have heard of the above term. So what is it? Let’s have a look.

Git or Git SCM (Source code management) is a version control system (VCS) that manages our source code and tracks the changes each developer has made to the project. It is a very powerful tool to work and collaborate on a single project by multiple developers simultaneously. It is so efficient that it tracks even a small change of putting just a line space.

Git was invented by Linus Torvalds (Principal developer of Linux kernel) in 2005 to coordinate with other developers for the development of Linux kernel.

Now some of you might be using GitHub, GitLab, or bitbucket. So what are they and how are they different from git?

These are cloud-based hosting providers for managing our git repositories online. Think of repos as different folders on your computer. We call it a repository (repo) here.

Now, do we need to learn different commands for using different platforms? The answer is No. All the platforms use git for version control. So you don’t need to learn different commands for different platforms, relax !!

How to start

There is a concept of branching in git. Let’s say you are developing a feature A for your project but for some reason you have to work on feature B first. So in that case either you need to complete developing feature A first and then go to B or you will just remove all your code written for feature A and start working on B. Sounds horrible right?

That’s where branches come to the rescue. You can now develop both the features simultaneously on different branches without disturbing your existing code. Branches are also used when multiple developers are working on different features at once.

When we first clone a remote project or upload our local project to git, it is tracked via a remote branch called “master” which is a default branch. But we can create multiple branches out of this branch and can give them custom names based on the feature we are working on.

Now, there are two ways of using this tool, GUI (Graphical user interface), and CLI (Command-line interface). For using the graphical interface you can download a desktop version of GitHub based on your operating system.

Here we are listing down some of the basic git commands:

  1. To initialize a git repository

       git init

  1. To stage the changes or telling git the changes you want to send to the remote repo

      git add <filename>

  • Note: If you want to stage multiple files at once use: git add .
  1. To commit changes

      git commit –m “your message”

  • -m flag is used to indicate a message
  1. To push code to the remote repository

      git push

  1. To pull the latest code changes from the repo

     git pull

6. To merge branches

  • Example: You currently are on the master branch and want to merge a branch “development” with it. Just write

      git merge development

  • Note: You must be on the branch you want to merge your code with.

7. To clone or copy a project from online repo to local computer

      git clone <repository_url>

8. To view the changes made to project files

      git status

 

Conclusion

It is a great way to contribute to the open-source community by providing help to projects made by others. Also, we can use others’ code in our projects if they’ve made their code public.  It also helps Companies to judge a candidate based on the contributions they made and code they‘ve written. So if you are a web developer, you must be having good knowledge of git and have also made some valuable contributions to the community.

Spread the love
Subscribe
Notify of
guest
1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
NK
NK
4 years ago

quite useful 😃