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 "[email protected]"
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! π»π₯