Learn Git from scratch with practical workflows, essential commands, branching strategies, and collaboration using GitHub.
Git is a distributed version control system used to:
Git stores snapshots of a project over time, allowing developers to experiment without losing previous work.
GitHub is a cloud platform built around Git.
It helps developers:
Git is the tool. GitHub is the hosting platform.
https://git-scm.com/downloads
git --version
Set the username and email associated with commits.
git config --global user.name "Your Name"
git config --global user.email "your@email.com"
Verify configuration:
git config --list
Git works using three main areas:
Working Directory
↓
git add
↓
Staging Area
↓
git commit
↓
Local Repository
↓
git push
↓
Remote Repository
| Area | Purpose |
|---|---|
| Working Directory | Files currently being edited |
| Staging Area | Changes prepared for commit |
| Repository | Stored project history |
git init
git clone https://github.com/user/repo.git
git status
git add file.txt
git add .
git commit -m "Add login feature"
git diff
git log
git log --oneline
git log --graph
View a specific commit:
git show <commit_id>
Branches allow independent development without affecting the main codebase.
git branch feature-login
git switch feature-login
git switch -c feature-login
git branch
git branch -d feature-login
Merge a feature branch into main:
git switch main
git merge feature-login
git remote add origin https://github.com/user/repo.git
git remote -v
git push -u origin main
git pull origin main
git fetch
git restore --staged file.txt
git restore file.txt
git commit --amend -m "Updated commit message"
Keeps changes locally.
git reset --soft HEAD~1
Removes changes permanently.
git reset --hard HEAD~1
Creates a new commit that undoes changes safely.
git revert <commit_id>
Temporarily store unfinished work.
git stash
git stash list
git stash apply
git stash drop
When two branches modify the same lines, Git creates a conflict.
After resolving conflicts manually:
git add .
git commit
Tags are commonly used for software releases.
git tag v1.0
git push origin v1.0
Prevent unnecessary files from entering version control.
Example:
__pycache__/
.env
*.log
node_modules/
| Term | Meaning |
|---|---|
| Repository | Project managed by Git |
| Commit | Snapshot of changes |
| Branch | Independent line of development |
| Merge | Combining branches |
| Clone | Copying a repository |
| Pull | Downloading latest changes |
| Push | Uploading commits |
| Remote | Online repository |
| HEAD | Current commit reference |
| Stash | Temporary storage for changes |
git init
git clone <url>
git status
git add .
git commit -m "message"
git push
git pull
git branch
git switch -c feature
git merge feature
git log --oneline
git stash
git reset --hard
.gitignore updatedgit clone <repo-url>
cd repo
git switch -c feature-login
git add .
git commit -m "Add login feature"
git push origin feature-login