PGDAC | Software Development Methodologies | Git and GitHub Notes
Git and GitHub are amongst the most popular tools in today's time. But a lot of people are still confused about the difference between Git and GitHub. So let's learn the difference between these two.
What is Version Control?
Version control systems are a category of software tools that helps in recording changes made to files by keeping track of modifications done in the code.
Why is it important?
A Version control system keeps track of changes made to a particular software and takes a snapshot of every modification. Let’s suppose a team of developer add some new functionalities to an application and the updated version is not working properly so as the version control system keeps track of our work so with the help of the version control system we can omit the new changes and continue with the previous version.
Git:
Git is a free and open-source distributed version control system designed to handle everything from small to very large projects with speed and efficiency.
It is used for tracking changes in your code.
It is used for tracking who made those changes.
It is also used for code collaboration In short, it is a system in which your project is kept.
How to Install Git?
Git installation on your PC appears to be simple. However, it also relies on your operating system. To install git on your system go to the official website and install the latest version of git on your operating system if you are a Linux user then, you only need to open your preferred terminal and run the script as follows:
Installation of Git on Mac using Brew:
brew install git
Installing Git on Windows:
You can download the setup from here or use the following command:
winget install --id Git.Git -e --source winget
Installing Git on Linux(Ubuntu):
sudo apt update
sudo apt install git
Click here to learn how to install git on other Linux/Unix-based OS.
Basic Git Commands:
Command | Function | Syntax |
git | show the git functions; also used to check if the present working directory has an active git repository or not | git |
git init | initializes a git repository in the present working directory | git init |
git status | displays the changes made to the repository | git status |
git add | bring all the files on stage to commit | git add . |
bring mentioned files on stage to commit | git add filename.txt | |
git restore | unstages the files that have been staged | git restore --staged <file.txt> |
git commit | commits the files that have been staged | git commit -m "<message>" |
git log | shows the history of commits made | git log |
git reset | reverts back to the said version history | git reset <hashcode> |
git stash | puts the unstaged change in the background | git stash |
git stash pop | brings the unstaged changes back on the stage from the background | git stash pop |
git stash clear | delete the unstaged changes from the background | git stash clear |
git remote add | attach a local repository to a GitHub repository | git remote add <link_alias> <github_repo_link> |
git remote -v | displays the GitHub links attached to the local repository | git remote -v |
git push | pushes the changes to the GitHub repository | git push <link_alias> <branch> |
git branch | creates a branch in the repository | git branch <branch_name> |
git checkout | changes the Head of the repository to the said branch | git checkout <branch_name> |
GitHub:
We may infer from the name that it is a Hub with initiatives, communities, etc. GitHub is a hosting service for Git repositories that offers a web-based graphical user interface. It is the world's biggest community. When a project is open-source, its specific repository is made public and receives numerous contributions.
The key benefits of GitHub are as follows:
It is easy to contribute to open-source projects via GitHub.
It helps to create an excellent document.
You can attract recruiters by showing off your work. If you have a profile on GitHub, you will have a higher chance of being recruited.
It allows your work to get out there in front of the public.
You can track changes in your code across versions.
What are Branches? Why make Branches?
By convention, the main branch is the default branch of any repository you create. It is recommended that any changes that are being committed or pushed should not be pushed directly to the main branch. Instead, another branch with a relevant name is created and the patches or changes are pushed to that branch.
This is done to protect unnecessary changes being pushed to the main branch. At times you will be working on some big code bases and you would take days to finalize your code. in such cases, pushing incomplete code to the main branch is not recommended as it will be displayed by default to anyone who ventures into your repo. this turns out to be very unprofessional. Instead, you can create a branch and push your changes to that branch. Once you're satisfied with the changes, you can then merge the secondary branch into the main branch.
This video will show you how exactly merging works behind the scenes.
Types of Merges in Git and GitHub:
When you are about to merge the commits from one branch to another, you will see that there are three options,
Commit and Merge:
Commit and Merge is the old-fashioned regular commit and merge option which commits all your changes one by one and then merges them to the specified branch.
While using Commit and Merge option, every single change is shown as a different commit in the branch.
Squash and Merge:
Squash and Merge clubs all your commits into a single commit and then merge it with the specified branch. Say you have created a patch-1 branch and have made 12 commits there, Squash and Merge will club all those commits into a single commit and then merge it into the specified branch.
After merging, to the outside world, all 12 changes will look as if they were made under a single commit.
Squash and Merge are useful when you have made some not-so-significant changes and it would not harm if the history of individual changes is not stored in individual commits.
Rebase and Merge:
In Rebase and Merge, instead and copying the commits to merge them into the specified branch, changes are committed into the specified branch directly. In simpler words, instead of copying the changes from one branch to another, in rebase and merge, you are moving the commits from one branch to another.
This removes the history of commits from the original branch and moves them into the target branch.
We will cover how to make your GitHub profile, how to add a cool and fancy introduction to your profile like mine mention below.
In the meantime, if you haven't already, you can visit my GitHub profile for reference and if you like what you see, you may drop me follow too🙂...
Thank you so much for reading.
I highly recommend you watch this video on Complete Git and GitHub Tutorial by Kunal Kushwaha
For additional information, you can read the blog Getting Started with Git and GitHub: A Complete Tutorial for Beginners by Riya Aggarwal
I hope this helps!! I strongly recommend you create your repository and host share your codes of all the assignments that are given by IACSD. This will help in building your credibility over time and also help you understand how Git and GitHub work. Share the link to your repository in the comment section below and I'll drop a follow on your GitHub profile🙂.
Thank you so much to everyone who was involved in my learning curve, especially Ravi Tambade, and Kunal Kushwaha for the resources and support.
Once again, Thank you for reading this article.
Happy Learning!!
Subscribe to my newsletter
Read articles from Abdul Ahad Sheikh directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Abdul Ahad Sheikh
Abdul Ahad Sheikh
Learning Fullstack Development using Java and .Net Aspiring Public Speaker Cofounder @BookBrotherhood Part-time Musician🎶 and Writer✒️ Live😊 | Love❤️ | Laugh😁