If you are learning to code in 2026, git and github tutorial for beginners is the most important search you will ever type. Git is the version control system that every professional developer uses to track changes in code, and GitHub is the online platform where those projects live. In this complete beginner tutorial, you will learn git basics from zero: how to install Git, configure it, make your first commit, work with branches, push code to GitHub, and recover from common mistakes — all with real commands you can run today.
Git vs GitHub: What Is the Difference?
New developers often mix these two up, so let us clear it up first. Git is a free, open-source version control tool that runs on your own computer. It takes snapshots of your project every time you “commit,” so you can see exactly what changed, when, and why. GitHub is a website (github.com) that hosts your Git repositories online, adds collaboration features like pull requests, and gives you a public portfolio of your work.
Think of it this way: Git is the camera, GitHub is the photo album you share with the world. This git and github tutorial for beginners covers both, because in real developer life they are always used together.
Setting Up Git: The First Step in This Git and GitHub Tutorial for Beginners
First, check whether Git is already installed:
git --version
If you see a version number like git version 2.44.0, you are good. If not, install it:
- Windows: Download the installer from git-scm.com and accept the defaults.
- macOS: Run
xcode-select --installin the terminal, or install via Homebrew withbrew install git. - Linux (Ubuntu/Debian): Run
sudo apt update && sudo apt install git.
Once installed, configure your identity. Git stamps your name and email on every commit, so set it once and forget it:
git config --global user.name "Your Name"
git config --global user.email "you@example.com"
Verify it worked:
git config --list
Tip: use the same email address as your GitHub account so your commits get linked to your profile. For the full reference, bookmark the official Git documentation.
Your First Repository: init, add, commit
This is the core workflow you will use every single day. To learn git basics properly, practice these three commands until they feel automatic.
Create a project folder and turn it into a Git repository:
mkdir my-first-project
cd my-first-project
git init
The git init command creates a hidden .git folder that will track everything from now on. Next, create a file and stage it:
echo "Hello, Git!" > readme.txt
git status
git add readme.txt
git status is your best friend — run it constantly to see what is staged, modified, or untracked. git add moves a file into the “staging area,” which is like a loading dock before the commit ships.
Now save the snapshot with a commit:
git commit -m "Add readme with greeting"
git log --oneline
The -m flag attaches a message describing the change. Write messages in the present tense (“Add feature” not “Added feature”). git log --oneline shows your history as a clean list. Congratulations — you just used version control like a professional.
To skip the staging step for files you have already committed once, use git commit -am "Update readme". The -a flag automatically stages tracked files.
Branching and Merging Explained
Branches let you work on a new feature without touching your stable code. Imagine your project is a tree: the main branch is the trunk, and every feature is a branch you can grow, test, and safely merge back in — or cut off if it fails.
Create and switch to a new branch:
git branch new-feature
git checkout new-feature
Or do both in one step with the modern command:
git switch -c new-feature
Make some changes, commit them, then merge the branch back into main:
git switch main
git merge new-feature
Sometimes Git cannot automatically combine two branches because the same lines changed in both. That is called a merge conflict, and it is not an error — it is Git asking you to decide. Open the conflicted file, look for the <<<<<<< markers, keep the version you want, delete the markers, then run:
git add conflicted-file.txt
git commit -m "Resolve merge conflict"
List your branches anytime with git branch, and delete a finished one with git branch -d new-feature.
Pushing Your Code to GitHub
Everything so far lived only on your computer. In this git and github tutorial for beginners, the next milestone is pushing your work online — step by step, GitHub for beginners style.
- Create a free account at github.com and click New repository.
- Name it (for example
my-first-project), keep it public, and do not initialize it with a README (you already have files locally). - GitHub shows you the commands to connect your local repo. Run these in your project folder:
git remote add origin https://github.com/YOUR-USERNAME/my-first-project.git
git branch -M main
git push -u origin main
The git remote add origin command links your local repo to GitHub. git push -u origin main uploads your commits and remembers the link, so future pushes are just git push. Refresh your GitHub page — your code is now live on the internet.
To pull changes from GitHub back to your machine (for example on a second computer), run git pull. Check the GitHub Docs for authentication options like personal access tokens, which replaced password-based pushing.
Pull Requests: How Collaboration Works
A pull request (PR) is how developers propose changes on GitHub. You push your branch, open a PR, teammates review the code, and then it gets merged. This is the workflow used by open-source projects and companies alike.
- Push your feature branch:
git push -u origin new-feature - On GitHub, click Compare & pull request.
- Write a clear title and description of what changed and why.
- Submit, wait for review, then click Merge pull request.
Good PR descriptions mention what you tested. Reviewers are far more likely to approve a PR that says “tested locally with…” than one with a blank description.
.gitignore: Keep Junk Out of Your Repo
A .gitignore file tells Git which files to never track — passwords, virtual environments, build folders, and OS files. Create one in your project root:
# Python
__pycache__/
*.pyc
.venv/
# Secrets
.env
# OS files
.DS_Store
Thumbs.db
# Build output
node_modules/
dist/
GitHub offers starter templates for every language when you create a repo. One caution: .gitignore only ignores untracked files. If you already committed a file, run git rm --cached filename to stop tracking it without deleting it from your disk.
Undoing Mistakes (Without Panic)
Everyone breaks things in Git, so no git and github tutorial for beginners is complete without a recovery plan. The key is knowing the right level of “undo” for each situation, from safest to most dangerous.
- Discard changes in a file (not yet staged):
git restore filename— returns the file to its last committed state. - Unstage a file (keep your edits):
git restore --staged filename— moves it back to unstaged. - Fix the last commit message:
git commit --amend -m "Corrected message"— rewrites only the most recent commit. - Undo the last commit but keep the changes:
git reset --soft HEAD~1— safe, your edits stay in the staging area. - Danger zone — throw away the last commit and its changes:
git reset --hard HEAD~1— this permanently deletes work. Only use it on commits you have not pushed to a shared branch.
Golden rule: never rewrite history (amend, reset, force-push) on branches other people are using. For shared mistakes, git revert creates a new commit that undoes an old one — safe for collaboration.
Your Daily Git Cheat Sheet
Tape this workflow to your monitor. This is the daily routine behind every git commands explained tutorial, and it covers 95% of real-world use:
git status # What changed?
git pull # Get the latest from the team
git checkout -b fix # Start a new branch
# ... edit files ...
git add . # Stage all changes
git commit -m "Fix the login bug"
git push # Send it to GitHub
# ... open a pull request, get it merged ...
git checkout main # Back to main
git pull # Update it
git branch -d fix # Clean up the finished branch
What’s Next
You now know more Git than most beginners pick up in a month from any git and github tutorial for beginners. The fastest way to make these commands stick is to use them daily on real projects. Start with our easy Python projects for beginners and commit your code after every feature — that habit alone will level you up fast. Since you will run all of these commands in a terminal, our Linux command line tutorial will make you feel at home in it. And when you are ready for the bigger picture, the complete roadmap for learning coding from scratch shows you exactly where Git fits into your journey as a developer.