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.
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.
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.
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.
Comments
Post a Comment