Basics About Git and GitHub

Akarsh Barar
3 min readJul 22, 2020

--

In this blog we are going to study how we can use git and GitHub in our projects. So first of all What is Git?

Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency.

So what is version control system?

Version Control system is a collection of software that keeps track of all the changes done in a project.

Some Version Control System are:

  1. Git
  2. SVN
  3. CVS
  4. Mercurial

In the above list Git and Mercurial are Distributed Version control system while SVN and CVS are Centralized Version Control System.

Centralized version control systems contain just one repository and each user gets their own working copy. You need to commit to reflecting your changes in the repository. It is possible for others to see your changes by updating.

Two operation on CVCS are

  • You commit
  • They update

Distributed version control systems contain multiple repositories. Each user has their own repository and working copy. Just committing your changes will not give others access to your changes. This is because commit will reflect those changes in your local repository and you need to push them in order to make them visible on the central repository. Similarly, When you update, you do not get other’s changes unless you have first pulled those changes into your repository.

Steps in DVCS are

  • You commit
  • You push
  • They pull
  • They update

Lets Get Started with Code

Lets create a project in our local system.

To initialize git in our project in terminal or command prompt type

git init

You will get output like this

Initialized empty Git repository in /home/akarsh/MediumGitnGithubFolder/.git/

To clone a existing git project

git clone <URL_OF_GITHUB_REPO>

This is copy the whole code in your local repository or local system.

To restore changes in any file (but the file should not be in staging area)

git restore <FILE_NAME>

This will restore any changes in the file and bring the original file to you back but the you need to know that the file should not be in staging area.

To add file in staging area

git add . // to add all file

git add <FILE_NAME> //to add a particular file

This will add file in the staging area it means that file is ready to commit.

To commit files

git commit -m “<MESSAGE FOR COMMITMENT>”

Commit is basically a checkpoint where you can revert back at any point of time if you face any problem.

To check existing branch

git branch

This will let you to check all the existing branches in local repo.

To create new branch

git branch <BRANCH_NAME>

This will create a branch for you and replicate your code from your current working branch. Branch name cannot be master.

To move to another created branch

git checkout <BRANCH_NAME>

This will let you work in another branch.

To merge branches

git merge <BRANCH_NAME>

This will help you to merge two branch. For example you are currently on dev branch and

To Download all changes

git fetch <Branch> || git pull

To get all changes from remote repository.

To push all changes to remote repo

get push -u <remote> <branch> <URL>

Congratulations you have learned most of the git and github. There are some code that comes in advance part of git and github that we will cover in some other blog.

In order to join my webinars follow me on instagram

https://www.instagram.com/mycodecave/

Make sure to subscribe to my YouTube Channel :

https://www.youtube.com/c/CodeCave

And follow on Instagram:

@mycodecave

Also on Facebook :

https://www.facebook.com/CodeCave-299370007293562

You can join my whatsapp flutter group the link is in the bio of instagram.

--

--

No responses yet