In the world of software development, over 90% of developers use a version control system, with Git being the most popular choice. Git is a distributed version control system that allow developers to track changes in code, collaborate seamlessly, and manage projects efficiently. GitHub is built on top of Git, a cloud-based platform that provides a user-friendly interface for hosting, reviewing, and sharing code. Together, Git and GitHub have become essential for modern development, enabling open-source collaboration and enterprise-level project management.
git and github
In this article, we will cover everything you need to know about Git and GitHub. Whether you're new to version control or looking to brush up on your skills, this guide will serve as a one-stop solution for learning about Git. Let's get started!
Introduction to Git
A version Control system is a system that maintains different versions of your project when working in a team or as an individual. (System managing changes to files) As the project progresses, new features get added to it. So, a version control system maintains all the different versions of your project for you, and you can roll back to any version you want without causing any trouble to you for maintaining different versions by giving names to them, like MyProject, MyProjectWithFeature1, etc.
Distributed Version control system means every collaborator (any developer working on a team project)has a local repository of the project in his/her local machine unlike central where team members should have an internet connection to every time update their work to the main central repository.
So, by distributed we mean: the project is distributed. A repository is an area that keeps all your project files, images, etc. In terms of GitHub: different versions of projects correspond to commits.
For more details on the introduction to Github, you can refer: Introduction to Github
Key Git Concepts
- Repository- A directory where git monitors your project files and records their revision history.
- Clone- It created a local copy of a remote repository on your machine.
- Stage - It Selects specific changes that you want Git to include in the next snapshot.
- Commit- It records the staged changes as a permanent version in the project history.
- Branch- Lets you develop new features or experiment without affecting the main project.
- Merge- Integrates changes from one branch into another.
- Pull- It fetches and applies updates from a remote repository to your local one.
- Push- It Uploads your local commits to a remote repository
Git Repository Structure
It consists of 4 parts:
- Working directory: This is your local directory where you make the project (write code) and make changes to it.
- Staging Area (or index): this is an area where you first need to put your project before committing. This is used for code review by other team members.
- Local Repository: this is your local repository where you commit changes to the project before pushing them to the central repository on Github. This is what is provided by the distributed version control system. This corresponds to the .git folder in our directory.
- Central Repository: This is the main project on the central server, a copy of which is with every team member as a local repository.
All the repository structure is internal to Git and is transparent to the developer.
Some commands which relate to repository structure:
// transfers your project from working directory
// to staging area.
git add .
// transfers your project from staging area to
// Local Repository.
git commit -m "your message here"
// transfers project from local to central repository.
// (requires internet)
git push
Note: For installation purposes on ubuntu, you can refer to this article: How to Install, Configure and Use GIT on Ubuntu?
Working with existing repos(git clone) and new repos(git init)
Git allows you to manage existing repository as well as new one.You can clone remote repository to work on a project that already exists, or initialize a new repository to begin tracking changes in a fresh project.
- Working with existing repos (git clone)- When you are collaborating on a project that already exists on the remote platform like Github, you don't need to start from scratch . Instead you can clone the repository to your local machine using:
bash git clone <repository-url>
This commands downloads the entire repository including its history, branches, and files.
bash git clone https://github.com/username/project
Now you have a full copy of the project and can start contributed locally.
- Started a new Repository (git init) - If you are beginning a brand new project you use:
bash
This Command will create a new git repository in your current directory. It sets up a . git folder that will track all your changes made to files inside the project.
bash mkdir my-project cd my-project git init
it will create a new folder , cd will redirect to current directory and git init will initializes a new empty repository.
How to Use git merge
Effectively in Git
git merge is used to combine changes from one branch into another. It allows teams to work on different features or fixes in isolation and then bring work together . Merging Preserves the history of both branches and is a key part of collaborative workflows in git.
- Switch the branch you want to merge into your changes
bash
- Merge Changes from another branch into the current branch
bash
- If there are merge conflicts resolve them manually, then stage the changes
bash
- Commit the merge if conflicts were resolved manually
bash
Creation of new Branch
Branches allows you to work on new features or fixes independently without affecting the main codebase. This isolates works and makes collaboration easier.
bash
Creating a new Branch without switching to it.
bash
Deletion of Branches
Once a branch has been emerged or no longer needed, you can delete it to keep your repo clean and organized.
bash git branch -d branch-name
Deletes the branch if it has already been merged.
- Force delete a local branch(unmerged changes)
bash git branch -D branch-name
Delete the branch regardless of its mege status
bash git push origin --delete branch-name
Removes the branch from the remote repository (e.g., GitHub).
How to Use git fetch
Effectively in Git
git fetch is used to download latest changes from a remote repository without automatically merging them into your current branch. It updates your local view of the remote branches, so you can review or merge changes .
- Fetch all branch from the remote
bash
Download update from the default remote (usually origin)
- Fetch from a specific remote
bash
- Fetch from a specific branch
bash git fetch origin feature-branch
Fetches only the feature-branch
from the remote.
- View changes after fetching
bash git log HEAD..origin/main
It shows changes to your main branch that aren't not in your local branch.
How to Use git stash
Effectively in Git
git stash is a handy git command that lets you temporarily save your uncommitted changes(both staged and unstaged) so you can switch branches or perform other tasks without losing your work. Once you're ready, you can reapply those changes exactly as you left them.
- Stash your current changes
bash
Saves your changes and reverts your working directory to a clean state.
- Stash with a custom message(recommended)
bash git stash save "WIP: added login form"
Adds a label so you remember what was stashed.
bash
Displays stashes like stash@{0}
, stash@{1}
, etc.
- Apply the most recent stash
XML
Restores the changes but keeps the stash in the list.
bash git stash apply stash@{1}
- Apply and delete a stash in one step
XML
XML
It removes all saved stashes.
Github
Github basically is a for-profit company owned by Microsoft, which hosts Git repositories online. It helps users share their git repository online, with other users, or access it remotely. You can also host a public repository for free on Github.
User share their repository online for various reasons including but not limited to project deployment, project sharing, open source contribution, helping out the community and many such.
Accessing Github central repository via HTTPS or SSH
Here, transfer project means transfer changes as git is very lightweight and works on changes in a project. It internally does the transfer by using Lossless Compression Techniques and transferring compressed files. Https is the default way to access Github central repository.
- By git remote add origin http_url: remote means the remote central repository. Origin corresponds to your central repository which you need to define (hereby giving HTTPS URL) in order to push changes to Github.
- Via SSH: connect to Linux or other servers remotely.
If you access Github by ssh you don't need to type your username and password every time you push changes to GitHub.
Terminal commands:
ssh-keygen -t rsa -b 4096 -C "[email protected]"
This does the ssh key generation using RSA cryptographic algorithm.
eval "$(ssh-agent -s)" -> enable information about local login session.
ssh-add ~/.ssh/id_rsa -> add to ssh key.
cat ~/.ssh/id_rsa (use .pub file if not able to connect)
add this ssh key to github.
Now, go to github settings -> new ssh key -> create key
ssh -T [email protected] -> activate ssh key (test connection)
Refresh your github Page.
Working with git - Important Git commands
Git user configuration (First Step)
git --version (to check git version)
git config --global user.name "your name here"
git config --global user.email "your email here"
These are the information attached to commits.
Initialize directory
git init
initializes your directory to work with git and makes a local repository. .git folder is made (OR)
git clone http_url
This is done if we have an existing git repository and we want to copy its content to a new place.
Connecting to the remoterepository
git remote add origin http_url/ssh_url
connect to the central repo to push/pull. pull means adopting the changes on the remote repository to your local repository. push merges the changes from your local repository to the remote repository.
git pull origin master
One should always first pull contents from the central repo before pushing so that you are updated with other team members' work. It helps prevent merge conflicts. Here, master means the master branch (in Git).
Stash Area in git
git stash
Whichever files are present in the staging area, it will move that files to stash before committing it.
git stash pop
Whenever we want files for commit from stash we should use this command.
git stash clear
By doing this, all files from stash area is been deleted.
Steps to add a file to a remote Repository:
First, your file is in your working directory, Move it to the staging area by typing:
git add -A (for all files and folders)
#To add all files only in the current directory
git add .
git status: here, untracked files mean files that you haven't added to the staging area. Changes are not staged for commit means you have staged the file earlier than you have made changes in that files in your working directory and the changes need to be staged once more. Changes ready to be committed: these are files that have been committed and are ready to be pushed to the central repository.
git status
git commit -a -m "message for commit"
-a: commit all files and for files that have been
staged earlier need not to be git add once more
-a option does that automatically.
git push origin master -> pushes your files to
github master branch
git push origin anyOtherBranch -> pushes any
other branch to github.
git log ; to see all your commits
git checkout commitObject(first 8 bits) file.txt->
revert back to this previous commit for file file.txt
Previous commits might be seen through the git log command.
HEAD -> pointer to our latest commit.
Ignoring files while committing
In many cases, the project creates a lot of logs and other irrelevant files which are to be ignored. So to ignore those files, we have to put their names in".gitignore" file.
touch .gitignore
echo "filename.ext" >>.gitignore
#to ignore all files with .log extension
echo "*.log" > .gitignore
Now the filenames written in the .gitignore file would be ignored while pushing a new commit. To get the changes between commits, commit, and working tree.
git diff
The 'git diff' command compares the staging area with the working directory and tells us the changes made. It compares the earlier information as well as the current modified information.
Branching in Git
create branch ->
git branch myBranch
or
git checkout -b myBranch -> make and switch to the
branch myBranch
Do the work in your branch. Then,
git checkout master ; to switch back to master branch
Now, merge contents with your myBranch By:
git merge myBranch (writing in master branch)
This merger makes a new commit.
Another way
git rebase myBranch
This merges the branch with the master in a serial fashion. Now,
git push origin master
To remove or delete a file
To remove. a file from the Git repository we use
git rm “file name”
To remove only from the staging area
git rm –cached “ file name”
Undoing change
To change all the files to as same as the previous commit then use
git checkout -f
Git vs Github
Git and GitHub are often mentioned together, but they serve different purposes. Git is a local tool used for tracking changes in your code, while GitHub is an online platform for hosting and sharing Git repositories. Together, they enable powerful version control and team collaboration in software development.
Feature | Git | Github |
---|
Type | Version control system (VCS) | Web based Hosting Service |
---|
Function | Tracks and manages code changes locally | Stores Git repositories in the cloud and enables collaboration |
---|
Installation | Must be installed on your system | Accessible through a web browser (no installation needed) |
---|
Usage | Used for local version control and branching | Used for sharing, reviewing, and managing Git projects online |
---|
Collaboration | Limited to local or manual sharing | Real-time collaboration with teams and contributors |
---|
Interface | Command-line tool (CLI) | Web-based UI and also supports Git CLI |
---|
Main Purpose | Track code history and manage changes locally | Centralized hub to host, view, and contribute to Git projects |
---|
Offline Support | Fully functional offline | Requires internet to access remote features |
---|
Contributing to Open Source
Open Source might be considered as a way where user across the globe may share their opinions, customizations or work together to solve an issue or to complete the desired project together. Many companies host there repositories online on Github to allow access to developers to make changes to their product. Some companies (not necessarily all) rewards their contributors in different ways.
You can contribute to any open source project on Github by forking it, making desired changes to the forked repository, and then opening a pull request. The project owner will review your project and will ask to improve it or will merge it.
Conclusion
In simple terms, Git is a powerful tool for managing your projects and code changes. It helps you keep your work organized, collaborate with others, and easily track your progress. Whether you're working alone or in a team, Git and GitHub make sure that you can manage your code, avoid errors, and never lose your work. It’s a must-learn for anyone who codes!
Similar Reads
GBlog - Explore Techâs Hottest Topics & Career Growth Hacks! Are you a tech person who's interested in learning new technology and decoding the future? GeeksforGeeks has a section for all tech enthusiasts where you can feed the tech monster inside you with high-level content. GBlog is your ultimate pitstop where innovation meets insight, and trends transform
7 min read
How To Become
How to become a Java Developer?Java is among the most preferred languages for development across the world common in website and mobile application development and for enterprise solutions. This article aims to explain various practical steps of how one can become a competent Java developer, the job description, and the general f
6 min read
How to Become a GenAI DeveloperGenerative AI is one of the most exciting and evolving areas of research in artificial intelligence, and it defines the relationship between technology and humans. With its ability to produce content from text, images, music, and videos, generative AI is contributing to the evolution of different in
8 min read
How to become a Cloud Network Engineer?Cloud Network Engineers play a vital role in ensuring that cloud services run smoothly for modern businesses. Big companies like Amazon, Google, and Microsoft are actively hiring DevOps engineers to manage and optimize their cloud infrastructures. As more organizations shift towards cloud computing,
11 min read
How to Become a DevSecOps EngineerA DevSecOps Engineer plays a crucial role in ensuring that security is embedded into every step of the software development process, combining development, security, and operations. Companies like Google, Amazon, Microsoft, IBM, and Netflix are actively hiring DevSecOps Engineers to protect their ap
9 min read
How to become an Automation Tester?Automation testers are those who focus on quality assurance and particularly specialize in the automation of the testing process. They design and run tests with various tools that automate the testing procedure to check the performance, functionality, and security of the software. An automation test
11 min read
Roadmap
Full Stack Developer Roadmap [2025 Updated]Web Developer/ Full Stack Web Developer - How do you feel when you tag yourself with such titles? A long journey takes place to be called by such names. In the beginning, you might feel bored or terrified, but, trust me, this is the most popular and interesting field one should work on. You can also
15 min read
Complete DevOps Roadmap - Beginner to AdvancedDevOps is considered a set of practices that combines the abilities of Software Development i.e Dev and IT Operations i.e Ops together, which results in delivering top-notch quality software fastly and more efficiently. Its focus is to encourage communication, collaboration, and integration between
8 min read
Machine Learning RoadmapNowadays, machine learning (ML) is a key tool for gaining insights from complex data and driving innovation in many industries. As more businesses rely on data for decision-making, having machine learning skills is more important than ever. By mastering ML, you can tackle real-world problems and cre
11 min read
Data Analyst Roadmap 2025 - A Complete GuideDreaming of a career where you unlock the secrets hidden within data and drive informed business decisions? Becoming a data analyst could be your perfect path! This comprehensive Data Analyst Roadmapfor beginners unveils everything you need to know about navigating this exciting field, including ess
7 min read
Interview Preparation
Interview Preparation RoadmapPreparing for technical interviews can often feel overwhelming due to the breadth of topics involved. However, a well-structured roadmap makes it easier to focus on the right subjects and systematically build your skills.This article outlines a step-by-step preparation plan covering key areas that y
5 min read
Top Interview Problems Asked in 2024 (Topic Wise)In this post, we present a list of the latest asked data structures and algorithms (DSA) coding questions to help you prepare for interviews at leading tech companies like Meta, Google, Amazon, Apple, Microsoft, etc. This list helps you to cover an extensive variety of DSA Coding questions topic-wis
2 min read
Top HR Interview Questions and Answers (2025)HR interviews can be daunting but they donât have to be. The bottom line in most hiring processes entails testing the personality of a candidate for their communication traits and company culture fit. Being at the initial or experienced levels of your career being prepared for commonly asked fresher
15+ min read
Database Administrator Interview QuestionsExplore these carefully collected Database Administrator (DBA) interview questions to equip yourself for a successful career move in the realm of database management. Familiarize yourself with the types of questions often encountered in technical assessments and problem-solving scenarios. Enhance yo
14 min read
Aptitude Questions and AnswersAptitude questions can be challenging, but with the right preparation and practice, you can tackle them with ease. Our comprehensive guide to aptitude questions and answers covers all the essential topics of Aptitude, including Quantitative Aptitude, Logical Reasoning, and Verbal Ability. Whether yo
4 min read
Project Ideas
10 Best Computer Science Projects Ideas for Final Year StudentsFinal year CSE projects are a student's big moment to showcase what they've learned. It's where they take all their computer science knowledge and use it to create something cool and useful. These projects can range from smart apps to blockchain systems that solve real-world problems.They're crucial
8 min read
Top 10 Mini Project Ideas For Computer Science StudentsProjects play a vital role in both enhancing skill sets and making a CV (curriculum vitae) stronger. If you have good projects in your CV, this undoubtedly makes a good impression on the recruiters. Also, If one wants to master some new skill, the only way is to implement it in some project. New tec
7 min read
30+ Web Development Projects with Source Code [2025]Web development is one of the most in-demand career paths in the IT industry, experiencing consistent growth of around 20â25% annually. Whether you're a student starting out or an experienced professional looking to switch or advance your career, it's essential to go beyond theory and demonstrate yo
4 min read
Top 10 Data Science Project Ideas for BeginnersData Science and its subfields can demoralize you at the initial stage if you're a beginner. The reason is that understanding the transitions in statistics, programming skills (like R and Python), and algorithms (whether supervised or unsupervised) is tough to remember as well as implement.Are you p
13 min read
Top 50 Java Project Ideas For Beginners and Advanced [Update 2025]Java is one of the most popular and versatile programming languages, known for its reliability, security, and platform independence. Developed by James Gosling in 1982, Java is widely used across industries like big data, mobile development, finance, and e-commerce.Building Java projects is an excel
15+ min read
10 Best Linux Project Ideas For BeginnersLinux is a famous operating system that looks complicated at first, but there are a few ways to master it. According to the statistics, more than 45% of professional developers work on Linux. That's why developing your skills in Linux can be a good option. As a Linux geek, you can get your hands on
7 min read
Top 7 Python Project Ideas for Beginners in 2025Python is one of the most popular programming languages due to its simplicity, versatility, and supportive community. Whether youâre a beginner eager to learn the basics or an experienced programmer looking to challenge your skills, there are countless Python projects to help you grow.Here is the li
6 min read
Certification
Top Machine Learning Certifications in 2025Machine learning is a critical skill in todayâs tech-driven world, affecting sectors such as healthcare, finance, retail, and others. As organizations depend more on artificial intelligence (AI) to solve complex problems, the need for machine learning professionals is skyrocketing. For those looking
9 min read
DevOps Certification - A Way to Enhance Growth OpportunitiesDevOps has become a trendy term. It plays an important role in enhancing the growth opportunity for both professionals and organizational setups. The investment of businesses in DevOps has also increased from 66% in 2015 to 76% in 2017. In 2019, 85-90% of businesses adopted DevOps technology. Based
4 min read
Top 10 Highest Paying CertificationsThe year 2025 has taught numerous things to the entire world, and from a career perspective, the importance of upskilling yourself has also surged in this particular period. People now have realized that to sustain in this rapidly growing tech world, you're constantly required to improve your skills
11 min read
Tech Certifications: Worth the Effort in 2025?One should stay ahead of the game in an ever-changing technological world. Therefore, if you want to proceed in your career, it is important to always be a step ahead. Tech certifications have become one of the most commonly used methods today that can help measure someoneâs proficiency levels and k
9 min read