Don't You Know Git & GitHub?

Don't You Know Git & GitHub?

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 —>

  1. What you searched

  2. 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 —>

  1. What things you added to the code.

  2. What things you removed from the code.

  3. 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?

CommandWhat it does
git initInitialise 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 logChecking the history of commits
git diffComparing the before & after states of working file
git pushPushing commits in a remote repo
git pullPulling / fetching & merging the changes made in a repo
git branchLists 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 stashSaving changes without committing
git stash popReapply stashed changes
git statusShows the condition of the working directory
git clone <url>Clone a repo from a URL
git fetchretrieve 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 —>

  1. An isolated branch is being made.

  2. Some work (bug fixing, feature updates etc) is being done.

  3. 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.