An open API service indexing awesome lists of open source software.

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.

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/)*



Markdown
Git
GitHub
Open Source
Version Control




Beginner Friendly
Documentation Project
Contributions Welcome

> ๐Ÿ“Œ *Version control is not just a tool โ€” it's a discipline. The cleaner your history, the clearer your future.*

---


Mastering WSL

---

## ๐Ÿ“š 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! ๐Ÿ’ป๐Ÿ”ฅ

---