GIT- VERSION CONTROL

EVERYTHING YOU NEED TO KNOW ABOUT GIT :)

Yadvi Bhalla
Innvotech
3 min readAug 15, 2020

--

I am gonna show you how to use command line to do things such as version control, how to clone repositories, how to fork, make pull requests, merge repositories and a whole bunch of really exciting things. So let’s get started!

To initialize git in our folder, use:

Let’s suppose you’re inside your working directory and here if you want to start tracking your changes, then you need to add your files to what’s called a STAGING AREA.This is actually a place in version control where you can decide which files you want to commit later. To see what’s currently inside your staging area, use the command:

It will show you the untracked files which will be shown in red color and in order to add your files to the staging area and to start tracking changes in it , use the command(use git add . to add all the files to the staging area):

And now if you use git status, you can see your file is added and it is in green color. So now it is ready to be committed.So let’s go ahead and commit this in local repository under version control using:

You can see what commits you have made using the following command:

Sometimes you might wonder, why not just go from the working directory straight to the local repository? Why do we need this extra step to go to the staging area??

Well, sometimes you might not want to add all of your files to be tracked or all of your files to be committed. So staging area is a good place to try and figure out what are the things that you want git to ignore and what are the things you want to be tracked.

So now let’s say i have been working on some file, and i have completely messed up everything.To check the differences between the current version and last version of my file,use:

I can actually revert the changes i have made locally in my working directory using:

Now we have learned to work on the local version of git locally. Now i am gonna talk about creating remote repositories.

To push your commits from local repository to remote repository in GitHub, use:

The -u flag(stands for upstream) will link your local repositories to your remote repositories. Our remote name is ‘origin’ and the branch name is ‘master’.Master branch is the default or the main branch of all your commits.

Now we looked at how to push your local repository to a remote repository on GitHub.

Working in a team:

To clone a remote repository to pull it to your local repository, use:

To create a separate branch locally, use

To check all the branches that exists,use:(the asterisk will show you the branch you’re currently in)

To switch to a particular branch, use the following command:

Make the necessary changes in your file.Then do:

To merge changes to the master branch:

To push changes to your branch, use:

Found this post useful? Share it!

--

--

Yadvi Bhalla
Innvotech

RedHat Certified Specialist in Containers and Kubernetes