Okay, so we had some small talks on Git and Version Control System yesterday. Let's get started with Git and git commands.
But before we move on to the basics, we need to install it first.
Follow the below process for the installation of Git:
Git Basics ✨
As we discussed in a previous blog, Git is an open-source distributed version-control system that keeps track of your source-code changes. There is no central server on which Git is dependent, you can clone (make a copy of the original) the full source code with the whole commit history on your local machine.
We are hearing that Git keeps track of changes made to source code. But how?
Behind the Scenes
There are a few terms in Git that you should know first.
Repository: You can call it your project folder, but it is remote. It is nothing more than a collection of source code.
The entire change tracking process can be divided into three steps:
- You modified something in your current working directory.
- You use
git addcommand to move your changes from your working directory to staging area.
- Now you commit changes using
git commitwhere changes are stored in the local repository and using
git pushyou push your changes to the remote repo.
Suppose someone from your team made any changes in the source code in a separate branch; now that changes have been accepted by your team lead, and you want to merge them to your main branch, then you can use
git merge to merge changes to the main branch.
Changes are merged to the main branch, but you are working on another branch with the same file, now if you try to push changes to the main branch, there will be a conflict. because the same file changed a few minutes ago and the changes were not reflected on your branch.
To resolve it, you must keep your branch in sync with the main branch. To do that you need to pull the changes from main using
There is one more case of forking.
If you are working on someone else's repo and you forked that repo and cloned it into your local machine, then you need to use
git fetch to fetch changes from the original repo to your forked repo. Then later you can use
In this case, you can't just merge or push the changes to the original repo's main branch. You need to send a pull request (PR) to the repository's maintainer or host. If he/she reviews and accepts your changes, then your changes are merged.
So that was all about Git and Git basics, but we are not done yet. This was just theory; practical stuff is coming in the next blog. So, stay tuned and subscribe to the newsletter.
Did you find this article valuable?
Support Shivlal Sharma by becoming a sponsor. Any amount is appreciated!