DEV Community

Shahriyar Al Mustakim Mitul
Shahriyar Al Mustakim Mitul

Posted on

DevOps Prerequisite (Part 4): Git and GitHub

Assuming this is the code we have:

Image description
When we start changing things regularly, it's hard to keep track of all of the details or get back to the previous files.

Image description
So, when the project becomes big and lots of contributors come in, we have to use source control management tool like git.

Image description
Using Git
Firstly, we initialize the total files and create a git repo.

Image description
Then we choose which files to track and which not to track.

Image description
Now, once you make any changes into any of the files. For example(main.py), it will track that down.

Image description

Now assume that you have multiple files and you want just one files changes to be confirmed and create a commit, you need to take that specific file to the staging area and then you can commit.

Note: Before commit, you have to take that file to the staging area.

Image description

Installing git and using it

First we install it ( here we used centos as our operating system)

Image description
Then you go to the folder where you are working and want to track. Then use this init command to initialize git.

Image description
Now we have no changes here to track , so we will see this.

Image description

We can track our desired files using the git add command

Image description

Now, assume that you have added some new codes and tried to check if git has been able to track that or not using git status.

Image description
Now we have taken it to the staging area.

Image description
Now we have committed our files.

Image description

Here all of the files which was kept for tracking has been added.

Remote repository

As your team increases, more and more people codes and you guys need to work centrally now.
So, you now need to keep an online central repository from where you will download (fetch/pull) codes or push (upload) codes.

Image description

Image description

Using remote repositories

now you want to track all of the files under your folder "my application" and then use the github remote repository for that.
Here you first locally add them all and take it to the staging area and then create your first commit.

Image description

You then go to GitHub and create a repository there.
In the beginning this repository will be empty and you will now upload (push) your commit to this remote repository.

Thus all the files will move to the remote repository too.

Image description
Now add this commit to your remote repository.

Image description
Now push this commit to the remote repo.

Image description

Here we have pushed to the master (which is main now) branch.

Image description

Now, when someone wants to get all of your codes, they first need to download it (clone it)

Image description

the user can then modify the codes and contribute too. Then there will he come to know about Pull requests (PR), Merge conflicts and many other terms.

But that's not for this blog.

Top comments (1)

Collapse
 
shrudra profile image
Sakhawat Hossain

Thanks for the informative post 😊