Git Tutorial
Git is an essential tool for developers, enabling them to manage and track project changes. Whether you're working on a solo project or collaborating with a team, Git keeps everything organized and under control.
This Git Tutorial, from beginner to advanced, will give you a complete understanding of the basics of Git, making it easy to learn and implement in your projects. You will learn about GitHub fundamentals and advanced concepts like branches, pushing, merge conflicts, and many useful Git Commands.

What is Git?
Git is an open-source distributed version control system (DVCS) that allows developers to track and manage changes to their codebase. You can easily manage small as well as large projects with high speed and efficiency by Git. Unlike traditional version control systems, Git allows multiple developers to work on a project simultaneously without interfering with each other's work. We can use Git privately as well as publically.
Let's try to understand it by taking an example - Geeksforgeeks Web Development team is building a website in which two developers are working one is Developer A who is working on the homepage and another is Developer B who works on the contact form. They both clone the Github repository, create separate branches, make changes and commit their work. After completion of their code, they push their code and open pull requests for review. After approval, the changes are merged into the main branch. By using Git they can easily track the changes without any kind of interference in each other's work and keep the project organized.
- Git was developed by Linus Torvalds in 2005 for Linux kernel development.
- Git 2.49.0 is the Latest Versions of GIT, released on March 2025.
Why Use Git?
Git offers numerous benefits to developers and development teams:
- Version Control: Git helps in tracking changes, allowing you to go back to previous states if something goes wrong.
- Collaboration: It enables multiple developers to work on a project simultaneously without interfering with each other’s work.
- Backup: Your entire project history is saved in a Git repository, providing a backup of all versions.
- Branching and Merging: Git’s branching model allows you to experiment with new features or bug fixes independently from the main project.
- Open Source Projects: Most open source projects use Git for version control. Learning Git allows you to contribute to these projects.
- Industry Standard: Git is widely used in the software industry, making it an essential skill for developers.
Working with Git
The Git workflow involves the following steps:
- Initializing a Repository: When you initialize a folder with Git, it becomes a repository. Git logs all changes made to a hidden folder within that repository.
- Staging Changes: Git marks modified files as “staged.” Staging prepares changes for a snapshot you want to keep.
- Committing Changes: Once staged changes are satisfactory, commit them. Git maintains a complete record of each commit.
- Create and switch branches: Use "
git branch"
to create a new branch, and "git checkout"
to switch to a different branch. - Merge branches: Use "
git merge"
to merge changes from one branch into another. This combines the commits from both branches into a single branch. - Push and pull changes: Use "
git push"
to upload your local commits to a remote repository, and "git pull"
to fetch and integrate remote changes into your local repository.
What is Github?
GitHub, a hosting service for Git repositories, allows you to access and download projects from any computer. Here’s what you can do with GitHub:
- Store Repositories: GitHub hosts your repositories.
- Collaborate: Work with other developers from any location.
- Version Control: Manage collaborative workflows using Git and GitHub.
Introduction to Git
- Version Control System
- Introduction and Installation of Git
- History of Git
- Git Features
- Introduction to GitHub
- Git Repository
- Git Features
- Bare Repositories in Git
- Git Ignore
- Readme.md File
- GitHub Readme File
- GitHub Labels
- Difference between CVS and GitHub
Git Basics
- Git – SubGit
- Git Environment Setup
- Using Git on CLI
- How to Setup a Repository
- Working with Git Repositories
- Using GitHub with SSH
- Working on Git with GUI
- Difference Between Git and GitHub
- Working on Git Bash
- States of a File in Git Working Directory
- Use of Submodules in GitHub
- How to Write Good Commit Messages on GitHub?
- Deleting a Local GitHub Repository
- Git Workflow Etiquettes
- Git Packfiles
- Git Garbage Collection
- Git Flow vs GitHub Flow
- Git – Difference Between HEAD, Working Tree and Index
Git Installation
- How to Use Git in Ubuntu
- How to Setup Git Server on Ubuntu?
- How to Add GIT Credentials in MacOS?
- How to add GIT credentials on Windows?
- How to add GIT credentials on Linux?
- How to Setup Git on Anypoint Studio?
- How to Install Git With Spyder
- How to Install Git on VMWare
- How to Install GIT in Conda?
- How to Install GIT on GoDaddy Server on Linux?
- How to Install Git on Windows Using Chocolatey?
- How to install GIT by NPM Packages?
- How to Install Git on Cygwin?
- How to Install Git Large File Storage on Linux?
- How to Install Sourcetree for GIT on Windows?
- How to Install Sourcetree for GIT in MacOs?
- How to Install Git on Raspberry Pi?
- How to Install Git on Termux?
- How to Set Up Git Using Git Config?
Git Commands
- Useful Git Commands and Basic Concepts
- Basic Git Commands with Examples
- Essential Git Commands
- Top 12 Most Used Git Commands For Developers
- Save a File in Git
- Difference between “add -A”, “add -u”, “add .”, and “add *”
- Difference between “git add -A” and “git add”
- Debugging in a Git
- How to Add Code on GitHub Repository?
- Pushing Changes to Git Repository
- Examining Git
- Git Checkout and Merge
- Revert a Git Commit
- Git Submodules
- Git Head
- Git Clean
- Git Rename
- Git Fork
- Git Init
- Git Add
- Git Commit
- Git Origin Master
- How to Set Upstream Branch on Git?
- Git Push
- Git Pull
- Git Pull and Fetch
- Git Merge
- Git Stash
- Git Remote
- Git Patch
- Git Patch Operations
- Git Rebase
- Git Clone
- Git Alias
- Git Ref and Reflog
- Git Undo Commit
- Git Undo
- Git Stage
- Git Squash
- Git Move Files
- Git diff
- Git Status
- Git Blame
- Git Index
- Git Prune
- Git Checkout and Merge
- Git Merge and Merge Conflicts
- Recovering Lost Commits in Git
- Git Tags
- Git Hooks
- Git Subtree
- Git – Filtering the Commit History
- Git - Cherry Pick
- Git – git-show Command Line Utility
- Git – Working Tree
- Git - Changing History
- Shallow Clone on Git Linux
- Sync your fork with a master in GitHub
- Error Searching and Handling in Git
- Delete a Git Branch Locally and Remotely
- How to Push Git Branch to Remote?
- How to Add an Empty Directory to a Git Repository?
- Difference Between Git Push Origin and Git Push Origin Master
- Difference Between Git remote prune, Git prune, on and Git fetch –prune
- Git – Difference Between Merging and Rebasing
- How to Use Git Log to Format the Commit History?
- How to Remove Local Untracked Files From Current Git Working Tree?
Git and GitHub
- Create a Repository on GitHub
- Introduction to Git Branch
- How to Add Code of Conduct to Your Project on GitHub?
- Difference Between Fork and Clone in GitHub
- How to Add Audio Files on README .md File in a GitHub Repository From the Local System?
- How to Add Videos on README .md File in a GitHub Repository?
- How to Upload a Project on GitHub
- How to Export a Git Project?
- How to Push a Project and Contribute on GitHub?
- How to Push Anything to GitHub using Git Bash?
- How to Push Folders From a Local PC to GitHub using Git Commands?
- How to Add Images on README .md File in a GitHub Repository From the Local System?
- How to Transfer Local Repository to GitHub Organization?
- How to Generate Personal Access Token in GitHub?
- How to Add GIFs on README .md File in a GitHub Repository?
- How to Change the Visibility of the GitHub Repository?
- Issues in GitHub
- Git – How to Solve “remote: Invalid username or password. fatal: Authentication failed”
- Git – A lock file already exists in the repository, which blocks this operation from completing
- Common Git Problems and Their Fixes
- How to add a README to your GitHub profile?
- How to Upload a Project through GitHub Desktop on GitHub
- How to configure an OAuth App from GitHub?
- How to move the most recent commit(s) to a new branch with Git
- How to Use GIT with R and RStudio?
- How to Use Git with Eclipse?
- Git–Pack Objects
Git and GitHub in VS Code
- How to Add GIT Credentials in VSCode?
- How to Clone a Project From GitHub using VSCode?
- How to Open a GitHub Repository in VS Code Online?
- Creating a Pull Request on any Public Repository from GitHub using VS Code
- How to Install GitHub Copilot on VSCode?
Git and GitHub in Android Studio
- How to Upload Project on GitHub from Android Studio
- How to Clone Android Project from GitHub in Android Studio?
- How to use Git Commands in Android Studio Terminal
- How to Create a New Branch on GitHub using Android Studio?
- How to Create a Pull Request on GitHub using Android Studio?
Git and GitHub in Pycharm
- How to Create a New Branch on Github using Pycharm?
- Create a Pull Request on GitHub using Pycharm
- How to Upload a Project on GitHub from Pycharm?
- How to Push Code to GitHub using Pycharm?
Git and GitHub Deployment
- How to deploy the Node.js app on Heroku from GitHub?
- Deployment of React Application using GitHub Pages
- How to Publish a Static Website on GitHub
- Host a free Static Website using GitHub
- Publish Websites on GitHub Pages with a Custom Domain
- How to Deploy a Basic Static HTML Website to Heroku using Git?
- How to Deploy Angular Application to Firebase using GitHub?
- How to Add Custom Domain To GitHub Pages?
- How to Deploy a Django Application to Heroku with Git CLI?
- How to create a cv using HTML and host it in GitHub?
- Deployment of Angular Application using Github Pages
- How to Build Portfolio Website And Host It on GitHub Pages?
Git Collaborating
- What is Git Collaboration
- What are GitHub Collaborators
- GitHub Discussion
- Forking Workflow in Open Source Ecosystem
- How to Clone Github Repository and Push Changes in Colaboratory?
- How to make your first Open Source Pull Request
- How to setup Gitlab Repository in Windows 10
- Merge Strategies in Git
- How to Handle Merge Conflicts
- GitHub App to Add or Remove Labels to Issues
- How to Create Pull Request on GitHub without Using any IDE?
- How to Clone Web Project from GitHub in Pycharm using Git?
- How to Clone a project from GitHub using Eclipse?
- How to Export Eclipse Projects to GitHub?
- Creating New Branch on Github without using any IDE
- How to Upload Project on GitHub from Jupyter Notebook?
Git Advanced
- How to Handle Big Repositories with Git?
- How to Protect Your Private Email Addresses in Git & Github?
- How to send an Email using Git send-email via Gmail?
- Dynamic Quote Generator for GitHub Readme
- Automating some git commands with Python
- How to Install and Use Git in Google Colab?
- Downloading gists from Github made simple
- Introduction to Bitbucket
- Difference between Bitbucket and GitHub
- Using Bitbucket as an extension to GitHub Capabilities
- Working on Bitbucket using Git
- Introduction to Mercurial
- Difference between MERCURIAL and GIT
- How to Make a GitHub Bot
- Jenkins and GIT Integration using SSH Key
- How to Trigger WebHooks without Events – Probot Github App
- Difference between Gitlab and GitHub
- Difference between Git and SVN
- Link your GitHub Account with R Studio
- Continuous Integration and Continuous Development(CI/CD)
- How to Add GIT Credentials in Jenkins?
- Implementation of CI/CD in .NET application Using Shell Executor on GitLab
- Implementation of CI/CD in Java application(Linux) Using Shell and Docker Executor on GitLab
- Implementation of CI/CD in C/C++ Application(Linux) Using Shell and Docker Executor on GitLab
- How to Publish Docker Image to Dockerhub Using Github Actions?
- Installing Private Git Server on K8s Cluster with Gitea and AKS
- Flutter – Building and Releasing APK using GitHub Actions
- How to Upload Android APK to Testers Group in Firebase Using GitHub Actions?
- Basic CI Workflow For Android using GitHub Actions
- GitHub Actions For Android
Git Workflow
A Git workflow is a set of guidelines that help teams collaborate effectively. Some common workflows include:
- Centralized Workflow: In centralized workflow every contributor commit to the main branch without using any other branch.
- Feature Branch Workflow: Each feature gets its own branch.
- GitFlow Workflow: A more structured workflow involving feature, release, and hotfix branches.
- Forking Workflow: Fork the project, make changes, and then create a pull request.
- Pull Request Workflow: The pull request workflow in Git is a collaborative development process that helps manage changes to a codebase, especially in team environments.
Internal Working of Git
Git uses a decentralized model where each developer has their own copy of the repository and works immediately on the project. Git manages the projects with repositories and can clone a project to operate locally on it.
With staging and committing it track changes and control. You can pull the latest code of the project to the local copy, and push local updates to the main projects.
Git vs GitHub
The following table gives you a comparison between Git and Github:
Aspect | Git | GitHub |
---|---|---|
Definition | Git is a distributed version control system that tracks changes in the source code. | GitHub is a cloud-based Git repository hosting service that enhances collaboration and code management. |
Purpose | To manage versions of code and track changes locally. | To host Git repositories online and allow collaboration and version control via Git. |
Installation | Git is a command-line tool installed locally on your machine. | GitHub is accessed via the web and requires no installation. |
Maintenance | Maintained by the Linux community. | Maintained by Microsoft since 2018. |
Focus | Git focuses on version control and managing code changes. | GitHub focuses on hosting, collaboration, and project management. |
History | Git was released in 2005 by Linus Torvalds. | GitHub was launched in 2008 as a platform for Git repository hosting. |
User Management | Git does not have built-in user management. | GitHub includes built-in user management, allowing for collaboration and permissions. |
Licensing | Git is open-source and free to use. | GitHub offers free-tier and paid plans with additional features. |
Tool Integration | Git has minimal external tool integration. | GitHub provides an active marketplace for integrations, including CI/CD, project management, and more. |
Interface | Git provides the Git GUI for graphical management. | GitHub provides GitHub Desktop and web interfaces for managing repositories. |
Competition | Git competes with CVS, Mercurial, and Subversion. | GitHub competes with GitLab, Bitbucket, and SourceForge. |
Best Practices for Git
The following are the best practices which everyone must follow while using Git:
- Commit Frequently: Commit your changes regularly to avoid large, hard-to-merge commits.
- Write Meaningful Commit Messages: Write clear, concise commit messages that describe what changes were made.
- Use Branches for Features: Always create a new branch for new features or bug fixes to keep the
main
branch stable. - Keep Your Repositories Organized: Maintain a clean and structured directory in your repository.
Common Git Problems and Their Fixes
Let's discuss some common git problems and how to fix it:
- Merge Conflicts: Always check for conflicting code before merging. Resolve conflicts manually and commit the resolved files.
- Detached HEAD State: When in a detached HEAD state, use
git checkout <branch_name>
to switch back to your branch. - Commit Not Pushed: Ensure that you have pushed your commits to the remote repository using
git push
.