Skip to main content

Git Basics and Local Usage

This blog is going to be on Git and a couple of very basic commands to run Git locally in our system. But before that, it is better to bust the myth, that “Git and GitHub are the same things”.

This is a very beginner-level misconception to assume Git and GitHub to be the same thing. Though they are related to each other, both of them serve different purposes. According to Wikipedia, Git is software for tracking changes in any set of files, usually used for coordinating work among programmers collaboratively developing source code during software development. In simple terms, Git is a version control system. While on the other hand, GitHub is a hosting platform where you can host your git repositories and share them with others. I guess the basic definition is clear, now we can take it to the next step. 

Downloading Git in your local system is very easy. You may follow any of the tutorials present on the Internet to install Git or maybe you can simply start installing on your own. The only thing you have to do is "next...next...next..........finish". (Download Link)

Once it is installed, follow the below steps: - 

1. Go to the location where you want to use Git. Right-click and open Git Bash.


2. Hit the command  git init  to initialize git there. You can see that a master branch is created. Master is the main branch of any repository. Branches are similar to versions. With each new branch created, we generate a new version.


3. Let’s open a notepad in that folder and write a sentence.


4. Now let’s try to commit this change in Git. Before committing, we need to inform Git to start tracking that particular file, which is also known as staging area. Enter the command  git add .  to move the notepad file to staging area.


5. Now commit the change to Git. Enter the command  git commit -m “some commit message”  . Immediately you will see some error related to identity unknown. If you are not getting this error, then probably you have already set your credentials.


6. You can use the mentioned command for setting up your email and name globally.

git config --global user.email “user_email”

git config --global user.name “user_name”


7. Hit the commit command once again. You can see that it got committed. It printed the number of files changed and the number of lines inserted. (+) sign refers to insertion of lines, and (-) sign refers to deletion of lines.


8. Add some more lines to your notepad and commit it. If you get the below error while committing, it simply means you need to hit the add command (step 4) before committing.



9. Hit the command  git log  to get history of the changes. The history will contain user information, timestamp and the commit message. The (HEAD -> master) refers to the current version. There is an alphanumeric sequence mentioned next to the word commit. Those are hash codes, which are unique to each commit.


10. Currently your notepad might contain the newly added line. If you want to go to the previous version of your notepad, to the previous commit, we can do it using the commit hash code. Hit the command git checkout 361de. You just need to mention some part of the hash code and Git is intelligent enough to pick the rest of it. 


11. If you open your notepad now, you will see that the newly added line has vanished. Git has brought the previous version of the notepad. Yes!! Git just made you travel back in time. In case you want to get back to present, or less jokingly, if you want to get back to your current version, hit the command  git switch -  . Voila!! You have your current version back.



This is just a glimpse of what Git can do. Besides these basic things, there are a lot of things that Git offers. There are concepts of branching, merging, remote repositories, etc. The more you read about it and practice it in your work, the better you get at it. 

Thank You!




Comments

Popular posts from this blog

Reminiscence

I was sitting in the second row as our class teacher called roll numbers for attendance. With each roll number called, I would turn around to see the face, which is supposed to be familiar as I meet them every day, but surprisingly brought a smile to my face as if I am meeting them after a long time. My best friend was sitting beside me too, just like any perfect day. Everyone talked to each other without our teacher stopping us, and the classroom seemed like a warm and cordial place to socialize. As time passed, not realizing the exact reason, I didn't want the period to get over. I didn't want that space to be disturbed. There was an urge in me to stop the time then and there. The sound of my alarm clock woke me up. Suddenly everything started to make sense. My "turning around" to see the faces, my "urge to stop time" everything seemed to be coherent. I was dreaming about my school days after five years of graduation. That's when I realized that I ha...

FOOD DELIVERY DATA VISUALIZATION PROJECT

I will be sharing a very interesting project with you all, where I will use Power BI to analyze the data of a Meal Delivery organization and answer a few of their business questions. While creating the dashboard, I will touch upon a few concepts named 'Calculated Column', 'Calculated Measures', etc. Wherever needed, I will mention some GCPs (Good Case Practices) in the process. ABOUT DATA The data used in this analysis has been taken from the internet and has no direct reference to any organization. It consists of three CSV files -  1. DEMAND DATA - It contains the historical data demand of various products by the centers. 2. MEAL LOOKUP - It contains the details about individual meals. 3. CENTER LOOKUP - It contains information about the various centers delivering the meals. SOLUTION  The very first step before we jump into any analysis is cleaning the data and creating the schema. I won't be covering the data cleaning and schema generation steps here as it goes...