Welcome to your all-in-one guide to mastering Git and GitHub! Whether you're a beginner just starting out or an experienced developer brushing up on advanced features, this guide covers everything with easy-to-understand commands, explanations, and best practices.
Visit the live site at https://atharvbyadav.github.io/Git-GitHub/
๐ Version control is not just a tool โ it's a discipline. The cleaner your history, the clearer your future.
- ๐ Git and GitHub Guide
- ๐ Table of Contents
- ๐ ๏ธ What is Git?
- โ๏ธ What is GitHub?
- ๐งฑ Installing Git
- ๐ง Git Configuration
- ๐งฐ Basic Git Commands
- ๐ Working with GitHub
- โ๏ธ Renaming & Removing Files
- ๐ฟ Branching & Merging
- ๐ฆ Stashing & Cleaning
- ๐ Rewriting History
- ๐ Logs & Diffs
- ๐ท๏ธ Tags
- ๐ฑ Rebasing & Cherry Picking
- ๐ฆ Git Submodules
- โก Git Aliases
- ๐ค Collaborating with Others
- โ๏ธ Resolving Merge Conflicts
- ๐ก Best Practices
- ๐ฏ Final Words
- ๐ Stay Connected
Git is like a time machine for your code. It tracks changes, helps multiple developers work together, and lets you rewind to any point in your project history.
- Keeps track of file changes
- Supports branching and merging
- Works offline and distributed
- Safe experimentation with branches
GitHub is where Git comes alive online. It's a platform for storing your Git repositories in the cloud, working with others, managing projects, and automating tasks with CI/CD.
- Host code in the cloud
- Collaborate via pull requests
- Track issues and tasks
- Automate with GitHub Actions
- Download Git from git-scm.com
- Follow the installation wizard (use defaults if unsure)
brew install git
sudo apt install git # Ubuntu/Debian
sudo yum install git # RHEL/CentOS
git --version
Configure Git globally so it knows who you are:
git config --global user.name "Pro User"
git config --global user.email "User@example.com"
git config --global core.editor "code --wait" # VSCode as default editor
git config --global color.ui auto # Enable colored output
git config --global alias.co checkout # Shortcut for checkout
Here's your day-to-day Git toolkit:
git init
Creates a new Git repository in the current folder.
git clone https://github.com/user/repo.git
Copies a remote repo to your local machine.
git status
Shows what's changed and what's ready to commit.
git add filename.ext # Stage one file
git add . # Stage everything
Tells Git what changes to include in the next commit.
git commit -m "Your commit message"
Saves your changes to the project history.
git log
git log --oneline
Shows the list of past commits.
git reset --soft HEAD~1
git remote add origin https://github.com/yourusername/repo.git
git branch -M main
git push -u origin main
Links your local Git project to a GitHub repository and pushes the main branch.
git push
Sends your local commits to GitHub.
git pull
Fetches and merges changes from GitHub into your local branch.
git clone https://github.com/user/repo.git
cd repo
# make changes
git add .
git commit -m "Initial commit"
git push origin main
git mv old_name.txt new_name.txt
Git tracks this as a rename (rather than delete + add).
git rm unwanted_file.txt
git commit -m "Renamed and removed files"
git push
git branch feature-xyz
git checkout feature-xyz
git checkout -b bugfix-login
git checkout main
git merge feature-xyz
git branch -d feature-xyz
git branch # local only
git branch -r # remote only
git branch -a # all
git push origin feature-xyz
git stash
Hides your uncommitted changes so you can switch branches safely.
git stash pop
git clean -f
Deletes untracked files. Use with caution!
git commit --amend
Edit the previous commit message or add forgotten changes.
git reset --soft HEAD~1
Keeps changes but removes the commit.
git reset --hard HEAD
git log
git log --oneline --graph --all
git diff # unstaged vs working dir
git diff --staged # staged vs last commit
git tag v1.0.0
git push origin v1.0.0
git tag
git checkout feature
git rebase main
Rewrites your branch history on top of another branch.
git cherry-pick <commit-hash>
Applies a specific commit to your current branch.
git submodule add https://github.com/user/repo.git path/to/module
git submodule init
git submodule update
Submodules let you include another Git repo inside your repo (e.g., plugins, libs).
Speed up commands using aliases:
git config --global alias.st status
git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.cm "commit -m"
Then use:
git st # Instead of git status
git co main # Instead of git checkout main
On GitHub, click Fork to create your own copy of someone else's repo.
๐ก Great for contributing to open-source projects!
git clone https://github.com/yourusername/repo.git
cd repo
git remote add upstream https://github.com/original/repo.git
This helps you keep your fork updated with the original.
git fetch upstream
git checkout main
git merge upstream/main
- Push your changes to your forked repo:
git push origin your-branch-name
- On GitHub, click "Compare & pull request".
- Write a clear title and description.
- Submit it for review.
โ Tip: Make sure your branch is up-to-date before opening a PR.
When Git can't merge changes automatically, it creates conflict markers in the file:
<<<<<<< HEAD
your version
=======
their version
>>>>>>> branch-name
- Edit the file to fix the conflict.
- Stage it again:
git add conflicted_file
- Commit the resolution:
git commit
โ
Commit messages should be clear and descriptive:
"Fix: resolve login token expiration issue"
โ
Use branches for every feature or bug fix.
Keeps main
clean and deployable.
โ Pull often to avoid diverging too far from the main branch.
โ Push regularly so work isn't lost.
โ
Don't commit sensitive files (like .env
, API keys).
โ Use `.gitignore to exclude files that shouldn't be tracked.
node_modules/
.env
*.log
.DS_Store
You got it! Here's a strong, inspiring, and professional ending to cap off your README:
Mastering Git and GitHub is more than just learning commands โ it's about developing a workflow that brings order, collaboration, and control to your development process. Whether you're building solo projects, working on a team, or contributing to open-source, Git is your time machine, safety net, and collaboration tool all in one.
Take your time to experiment, break things, fix them, and learn โ that's how real growth happens.
๐ง "The best developers aren't those who never make mistakes โ they're the ones who track, manage, and learn from them."
Keep pushing code, keep pulling knowledge, and let your commit history tell the story of your evolution as a developer. ๐ฑโจ
If you found this guide helpful, give the repository a โญ on GitHub, share it with others, or fork it and build your own version!
Have suggestions or want to contribute? Open a pull request โ collaboration starts here. ๐ก
Ready to take the next step?
"Go build. Break things. Fix them. Version everything."
Happy coding! ๐ป๐ฅ