A Brief Introduction to Git

Randika Padmashali
3 min readMar 7, 2021

Git is one of the most popular version control software nowadays. Git keeps track of all the changes you make to files so you can see what you have done and revert to earlier versions if possible. Git also facilitates teamwork by allowing different people’s modifications to be merged into one source. If you write code that you only use or collaborate as part of a team, Git will be useful to you.

Git is software that runs on your computer. It can access via a command line or a GUI. Your computer saves your files and their records. You can also store a copy of the files and their revision history using web hosts (such as GitHub or Bitbucket). Having a central place where you can upload your changes and download changes from others, allowing you to work with other developers more easily. Git can automatically merge the changes, So two parties will work on separate sections of the same file at the same time and then merge their modifications without losing each other’s work.

Git Repositories

A repository is a collection of files of different versions of a project. These files are imported from the repository into the user’s local server for further updates and changes to the file’s content. The process which copying content from an existing Git repository with the help of various Git tools is called cloning. Once the cloning process is complete, the user gets the complete repository on his local machine. Users can also create a new repository or delete an existing repository.

Remote Repositories

Git repository which provides online hosts such as GitHub or Bitbucket called a remote repo. It gives you a centrally located place where you can upload your changes and download changes from others, letting you collaborate more easily with other developers.

After setting up a remote repository, you can push(upload) your files and revision history to it. After someone else makes changes to a remote repository, you can pull (download) their changes into your local repo.

How do we tell Git to record our changes?

Every change recorded to a file or set of files is called a commit.

First, we must tell Git what files we want to commit. This is known as staging and uses the add command Why do we have to do this? Why aren’t we able to simply commit the file? Assume you’re operating on more than one file, but only one is able to be committed. You don’t want to be forced to commit all files; only the one that’s ready should be committed. That is why the add command in Git is important. We add files to a staging area, and then we commit the files that have been staged.

Branches

Git allows you to branch out from the original codebase. This makes it easier to collaborate with other developers and allows you a lot of workflow versatility. When you’re done, merge the new feature branch into the master branch, preserving both the new feature and the rush update.

If you are made changes on a new branch in some project which managing another person and you need to merge it with a master branch, you can create a pull request to notify the person who manages that project to review your code. Then can discuss the changes and decide if want to merge them or not.

Basic Git Commands

Git init — Create a new local repository

Git clone — Create a working copy of a local repository

Git add — Add one or more files to the staging

Git commit — Commit changes to head

Git push — Send changes to the master branch of your remote repository

Git pull — Fetch and merge changes on the remote server to your working directory

--

--