Welcome learners!
If the answer to the above question is ‘NO’, then you have come to the right place.
After reading this documentation on Git, you will feel confident over git commands, version controlling and everything important related to the matter.
The documentation will be easy to comprehend and you will learn through question - answer format
So, the first question that comes to the mind is ‘What is Git & Github?’
What is Git & Github?
Have you ever gone through your browser history? Well, probably everybody would have gone through it. You would have noticed that it shows the following things —>
What you searched
When you searched (Both Date & Time)
Similarly, Git is a tool that you can use to record the history of your code! It lets you record the following things —>
What things you added to the code.
What things you removed from the code.
When did you make those changes.
Just like you can remove an entry in your browser history, you can also reverse the changes that you make to your code. (This is the superpower of Git)
In formal sense, Git is a version control system (VCS) that records the changes in the files/codebases and enables the people to collaboratively work on a project.
What is Version Control?
You would have seen different version of a software (iOS 18.1, iOS 18.1.1). This changing or upgrading of software is nothing but basically few or several changes in the codebase itself. Managing this change in codebase or recording a history of this change (This is what Git does) is Version Control.
Therefore, Git is a Version Control System (VCS).
What Are Repositories?
Before going forward it is important to make sure that you know what is a repository.
Why is it important? It is important because all of the work that you are going to do is going to revolve around repositories.
Now, answering the main question, a repository is a directory or a place which stores all the code files, documentations and version control histories. Pretty much everything, right!
The more fluent you are with repositories the better the workflow
The more fluent you are with repositories the better the collaboration
What Are Some Basic Git Commands?
Command | What it does |
git init | Initialise a new git repo (short form for repository) |
git add <file> | Staging a particular file for commit |
git add . | Staging all of the files in the current directory for commit |
git commit -m “message” | Committing the staged changes with a message |
git log | Checking the history of commits |
git diff | Comparing the before & after states of working file |
git push | Pushing commits in a remote repo |
git pull | Pulling / fetching & merging the changes made in a repo |
git branch | Lists down all the branches |
git branch <name> | Creates a new branch |
git checkout <branch> | Switch to a specific branch |
git merge <branch> | Merge a branch to a current branch |
git reset <file> | Unstage a file (file remains modified) |
git reset —hard <file> | Unstage a file (modifications are removed as well) (use cautiously) |
git stash | Saving changes without committing |
git stash pop | Reapply stashed changes |
git status | Shows the condition of the working directory |
git clone <url> | Clone a repo from a URL |
git fetch | retrieve latest changes from a remote repo (does not merge them) |
git remote add <name> <url> | Add a remote repo |
git rebase <branch> | Reapply commits on top of another branch |
What Is diff in git diff?
You might be wondering ‘what difference are we talking about? ‘
The difference here is about the state of codebase before the commit and state of codebase after the commit.
Red Line → This was removed
Green Line → This was added
What is Remote Repo & Local Repo?
Another important concept related to repositories is difference between Remote Repo & Local Repo.
Remote Repository is hosted on a remote server or a cloud service (GitHub, GitLab)while Local Repo is not hosted somewhere but resides on your local machine.
What Is A Branch?
The above figure depicts the branching in the most easy to visualise manner.
Master Branch is also known as Main Branch.
The above figure shows exactly that —>
An isolated branch is being made.
Some work (bug fixing, feature updates etc) is being done.
Branch is being merged again with the Master Branch.
Benefit of branching —> You can work on a branch independently without compromising the main codebase and when you feel that sufficient work (bug fixing, feature updates etc) has been done, you can merge the branch again with the Master Branch.
NOTE Initially, the branch that you make will have the exact copied code of the parent branch (Master Branch, in the above diagram) & then you will work on it and then you will finally merge it.
What Is The Caution Regarding Git Commit Command?
git commit -m “message”
There are various rules/guidelines regarding the ‘message’ section in the above command.
In some companies, the rule is to write only in present tense while some prefer past tense.
Sometimes, additional rules/guidelines can also be drawn out on depending upon the company’s working methodology.
What Is GitHub?
GitHub, as discussed in one of the sections above, is a remote server for Git Repositories.
It is a web-based platform that provides user-friendly interface for storing, sharing and collaborating code with team members.
There are other alternatives as well. For example → GitLab, BitBucket, SourceForge etc.
The foundation here is Git.
GitHub is based on Git and provides User-Interface to leverage Git providing collaborative tools.
Above image pretty much tells you what the interface of GitHub looks like.
Conclusion
Git & GitHub both are of immense importance in the field of software. Any budding developer or even a senior developer should know the basics of it and this blog is all about it.