https://github.com/atharvbyadav/git-github
๐ A complete beginner-to-advanced guide to mastering Git and GitHub โ packed with essential commands, practical workflows, and collaboration best practices.
https://github.com/atharvbyadav/git-github
cheatsheet cli collaboration developer-tools documentation git git-guide git-workflow github markdown open-source version-control
Last synced: 22 days ago
JSON representation
๐ A complete beginner-to-advanced guide to mastering Git and GitHub โ packed with essential commands, practical workflows, and collaboration best practices.
- Host: GitHub
- URL: https://github.com/atharvbyadav/git-github
- Owner: atharvbyadav
- License: mit
- Created: 2025-01-10T09:38:51.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-06-10T06:29:57.000Z (9 months ago)
- Last Synced: 2025-10-30T19:43:32.690Z (5 months ago)
- Topics: cheatsheet, cli, collaboration, developer-tools, documentation, git, git-guide, git-workflow, github, markdown, open-source, version-control
- Language: HTML
- Homepage: https://atharvbyadav.github.io/Git-GitHub/
- Size: 3.45 MB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# ๐ Git and GitHub Guide
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/](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.*
---
---
## ๐ Table of Contents
- [๐ Git and GitHub Guide](#-git-and-github-guide)
- [๐ Table of Contents](#-table-of-contents)
- [๐ ๏ธ What is Git?](#๏ธ-what-is-git)
- [๐ Key Features:](#-key-features)
- [โ๏ธ What is GitHub?](#๏ธ-what-is-github)
- [๐ก Why Use GitHub?](#-why-use-github)
- [๐งฑ Installing Git](#-installing-git)
- [๐ฝ For Windows:](#-for-windows)
- [๐ For macOS:](#-for-macos)
- [๐ง For Linux:](#-for-linux)
- [โ
Verify Installation:](#-verify-installation)
- [๐ง Git Configuration](#-git-configuration)
- [Optional Goodies:](#optional-goodies)
- [๐งฐ Basic Git Commands](#-basic-git-commands)
- [๐น Initialize a Repository](#-initialize-a-repository)
- [๐น Clone a Repository](#-clone-a-repository)
- [๐น Check Status](#-check-status)
- [๐น Stage Files](#-stage-files)
- [๐น Commit Changes](#-commit-changes)
- [๐น View Commit History](#-view-commit-history)
- [๐น Undo Last Commit (Keep Changes)](#-undo-last-commit-keep-changes)
- [๐ Working with GitHub](#-working-with-github)
- [๐ Connect Local Repo to GitHub](#-connect-local-repo-to-github)
- [๐ Push Changes](#-push-changes)
- [โฌ๏ธ Pull Changes](#๏ธ-pull-changes)
- [๐ Clone Then Push to New Repo](#-clone-then-push-to-new-repo)
- [โ๏ธ Renaming \& Removing Files](#๏ธ-renaming--removing-files)
- [๐ Rename a File](#-rename-a-file)
- [๐๏ธ Remove a File](#๏ธ-remove-a-file)
- [โ
Commit and Push](#-commit-and-push)
- [๐ฟ Branching \& Merging](#-branching--merging)
- [๐ฑ Create a New Branch](#-create-a-new-branch)
- [๐ Switch to a Branch](#-switch-to-a-branch)
- [โ Create \& Switch in One Step](#-create--switch-in-one-step)
- [๐ Merge a Branch into Main](#-merge-a-branch-into-main)
- [๐งน Delete a Merged Branch](#-delete-a-merged-branch)
- [๐งญ See All Branches](#-see-all-branches)
- [๐ Push a Branch to GitHub](#-push-a-branch-to-github)
- [๐ฆ Stashing \& Cleaning](#-stashing--cleaning)
- [๐งณ Temporarily Save Changes (Stash)](#-temporarily-save-changes-stash)
- [๐ฏ Reapply Stashed Changes](#-reapply-stashed-changes)
- [๐งผ Remove Untracked Files](#-remove-untracked-files)
- [๐ Rewriting History](#-rewriting-history)
- [๐ Amend Last Commit](#-amend-last-commit)
- [๐ซ Undo a Commit (Soft Reset)](#-undo-a-commit-soft-reset)
- [๐ฅ Hard Reset to Last Commit](#-hard-reset-to-last-commit)
- [๐ Logs \& Diffs](#-logs--diffs)
- [๐ View Commit History](#-view-commit-history-1)
- [๐ View File Differences](#-view-file-differences)
- [๐ท๏ธ Tags](#๏ธ-tags)
- [๐ Create a Tag](#-create-a-tag)
- [๐ Push Tags to GitHub](#-push-tags-to-github)
- [๐ List Tags](#-list-tags)
- [๐ฑ Rebasing \& Cherry Picking](#-rebasing--cherry-picking)
- [๐ Rebase a Branch](#-rebase-a-branch)
- [๐ Cherry Pick a Commit](#-cherry-pick-a-commit)
- [๐ฆ Git Submodules](#-git-submodules)
- [โ Add a Submodule](#-add-a-submodule)
- [๐ Init \& Update](#-init--update)
- [โก Git Aliases](#-git-aliases)
- [๐ค Collaborating with Others](#-collaborating-with-others)
- [๐ด Fork a Repository](#-fork-a-repository)
- [๐ฒ Clone Your Fork](#-clone-your-fork)
- [๐ Add the Original Repository as "Upstream"](#-add-the-original-repository-as-upstream)
- [๐ Sync Your Fork](#-sync-your-fork)
- [๐ค Create a Pull Request (PR)](#-create-a-pull-request-pr)
- [โ๏ธ Resolving Merge Conflicts](#๏ธ-resolving-merge-conflicts)
- [๐งฉ To Resolve:](#-to-resolve)
- [๐ก Best Practices](#-best-practices)
- [๐ Sample `.gitignore` for Node.js](#-sample-gitignore-for-nodejs)
- [๐ฏ Final Words](#-final-words)
- [๐ Stay Connected](#-stay-connected)
---
## ๐ ๏ธ What is Git?
**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.
### ๐ Key Features:
- Keeps track of file changes
- Supports branching and merging
- Works offline and distributed
- Safe experimentation with branches
---
## โ๏ธ What is GitHub?
**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.
### ๐ก Why Use GitHub?
- Host code in the cloud
- Collaborate via pull requests
- Track issues and tasks
- Automate with GitHub Actions
---
## ๐งฑ Installing Git
### ๐ฝ For Windows:
- Download Git from [git-scm.com](https://git-scm.com/)
- Follow the installation wizard (use defaults if unsure)
### ๐ For macOS:
```bash
brew install git
```
### ๐ง For Linux:
```bash
sudo apt install git # Ubuntu/Debian
sudo yum install git # RHEL/CentOS
```
### โ
Verify Installation:
```bash
git --version
```
---
## ๐ง Git Configuration
Configure Git globally so it knows who you are:
```bash
git config --global user.name "Pro User"
git config --global user.email "User@example.com"
```
### Optional Goodies:
```bash
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
```
---
## ๐งฐ Basic Git Commands
Here's your day-to-day Git toolkit:
### ๐น Initialize a Repository
```bash
git init
```
*Creates a new Git repository in the current folder.*
---
### ๐น Clone a Repository
```bash
git clone https://github.com/user/repo.git
```
*Copies a remote repo to your local machine.*
---
### ๐น Check Status
```bash
git status
```
*Shows what's changed and what's ready to commit.*
---
### ๐น Stage Files
```bash
git add filename.ext # Stage one file
git add . # Stage everything
```
*Tells Git what changes to include in the next commit.*
---
### ๐น Commit Changes
```bash
git commit -m "Your commit message"
```
*Saves your changes to the project history.*
---
### ๐น View Commit History
```bash
git log
git log --oneline
```
*Shows the list of past commits.*
---
### ๐น Undo Last Commit (Keep Changes)
```bash
git reset --soft HEAD~1
```
---
## ๐ Working with GitHub
### ๐ Connect Local Repo to GitHub
```bash
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.*
---
### ๐ Push Changes
```bash
git push
```
*Sends your local commits to GitHub.*
---
### โฌ๏ธ Pull Changes
```bash
git pull
```
*Fetches and merges changes from GitHub into your local branch.*
---
### ๐ Clone Then Push to New Repo
```bash
git clone https://github.com/user/repo.git
cd repo
# make changes
git add .
git commit -m "Initial commit"
git push origin main
```
---
## โ๏ธ Renaming & Removing Files
### ๐ Rename a File
```bash
git mv old_name.txt new_name.txt
```
*Git tracks this as a rename (rather than delete + add).*
---
### ๐๏ธ Remove a File
```bash
git rm unwanted_file.txt
```
### โ
Commit and Push
```bash
git commit -m "Renamed and removed files"
git push
```
---
## ๐ฟ Branching & Merging
### ๐ฑ Create a New Branch
```bash
git branch feature-xyz
```
### ๐ Switch to a Branch
```bash
git checkout feature-xyz
```
### โ Create & Switch in One Step
```bash
git checkout -b bugfix-login
```
---
### ๐ Merge a Branch into Main
```bash
git checkout main
git merge feature-xyz
```
---
### ๐งน Delete a Merged Branch
```bash
git branch -d feature-xyz
```
---
### ๐งญ See All Branches
```bash
git branch # local only
git branch -r # remote only
git branch -a # all
```
---
### ๐ Push a Branch to GitHub
```bash
git push origin feature-xyz
```
---
## ๐ฆ Stashing & Cleaning
### ๐งณ Temporarily Save Changes (Stash)
```bash
git stash
```
*Hides your uncommitted changes so you can switch branches safely.*
### ๐ฏ Reapply Stashed Changes
```bash
git stash pop
```
### ๐งผ Remove Untracked Files
```bash
git clean -f
```
*Deletes untracked files. Use with caution!*
---
## ๐ Rewriting History
### ๐ Amend Last Commit
```bash
git commit --amend
```
*Edit the previous commit message or add forgotten changes.*
---
### ๐ซ Undo a Commit (Soft Reset)
```bash
git reset --soft HEAD~1
```
*Keeps changes but removes the commit.*
### ๐ฅ Hard Reset to Last Commit
```bash
git reset --hard HEAD
```
*โ ๏ธ WARNING: This erases all changes permanently.*
---
## ๐ Logs & Diffs
### ๐ View Commit History
```bash
git log
git log --oneline --graph --all
```
### ๐ View File Differences
```bash
git diff # unstaged vs working dir
git diff --staged # staged vs last commit
```
---
## ๐ท๏ธ Tags
### ๐ Create a Tag
```bash
git tag v1.0.0
```
### ๐ Push Tags to GitHub
```bash
git push origin v1.0.0
```
### ๐ List Tags
```bash
git tag
```
---
## ๐ฑ Rebasing & Cherry Picking
### ๐ Rebase a Branch
```bash
git checkout feature
git rebase main
```
*Rewrites your branch history on top of another branch.*
---
### ๐ Cherry Pick a Commit
```bash
git cherry-pick
```
*Applies a specific commit to your current branch.*
---
## ๐ฆ Git Submodules
### โ Add a Submodule
```bash
git submodule add https://github.com/user/repo.git path/to/module
```
### ๐ Init & Update
```bash
git submodule init
git submodule update
```
*Submodules let you include another Git repo inside your repo (e.g., plugins, libs).*
---
## โก Git Aliases
Speed up commands using aliases:
```bash
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:
```bash
git st # Instead of git status
git co main # Instead of git checkout main
```
---
## ๐ค Collaborating with Others
### ๐ด Fork a Repository
On GitHub, click **Fork** to create your own copy of someone else's repo.
> ๐ก Great for contributing to open-source projects!
---
### ๐ฒ Clone Your Fork
```bash
git clone https://github.com/yourusername/repo.git
cd repo
```
---
### ๐ Add the Original Repository as "Upstream"
```bash
git remote add upstream https://github.com/original/repo.git
```
*This helps you keep your fork updated with the original.*
---
### ๐ Sync Your Fork
```bash
git fetch upstream
git checkout main
git merge upstream/main
```
---
### ๐ค Create a Pull Request (PR)
1. Push your changes to your forked repo:
```bash
git push origin your-branch-name
```
2. On GitHub, click **"Compare & pull request"**.
3. Write a clear title and description.
4. Submit it for review.
> โ
Tip: Make sure your branch is up-to-date before opening a PR.
---
## โ๏ธ Resolving Merge Conflicts
When Git can't merge changes automatically, it creates **conflict markers** in the file:
```txt
<<<<<<< HEAD
your version
=======
their version
>>>>>>> branch-name
```
### ๐งฉ To Resolve:
1. Edit the file to fix the conflict.
2. Stage it again:
```bash
git add conflicted_file
```
3. Commit the resolution:
```bash
git commit
```
---
## ๐ก Best Practices
โ
**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.
---
### ๐ Sample `.gitignore` for Node.js
```gitignore
node_modules/
.env
*.log
.DS_Store
```
---
## ๐ฏ Final Words
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. ๐ฑโจ
---
## ๐ Stay Connected
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! ๐ป๐ฅ
---