/Git-GitHub

๐Ÿ“š A complete beginner-to-advanced guide to mastering Git and GitHub โ€” packed with essential commands, practical workflows, and collaboration best practices.

Primary LanguageHTMLMIT LicenseMIT

๐Ÿš€ 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/

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


๐Ÿ› ๏ธ 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
  • Follow the installation wizard (use defaults if unsure)

๐ŸŽ For macOS:

brew install git

๐Ÿง For Linux:

sudo apt install git       # Ubuntu/Debian
sudo yum install git       # RHEL/CentOS

โœ… Verify Installation:

git --version

๐Ÿ”ง Git Configuration

Configure Git globally so it knows who you are:

git config --global user.name "Pro User"
git config --global user.email "User@example.com"

Optional Goodies:

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

git init

Creates a new Git repository in the current folder.


๐Ÿ”น Clone a Repository

git clone https://github.com/user/repo.git

Copies a remote repo to your local machine.


๐Ÿ”น Check Status

git status

Shows what's changed and what's ready to commit.


๐Ÿ”น Stage Files

git add filename.ext     # Stage one file
git add .                # Stage everything

Tells Git what changes to include in the next commit.


๐Ÿ”น Commit Changes

git commit -m "Your commit message"

Saves your changes to the project history.


๐Ÿ”น View Commit History

git log
git log --oneline

Shows the list of past commits.


๐Ÿ”น Undo Last Commit (Keep Changes)

git reset --soft HEAD~1

๐ŸŒ Working with GitHub

๐Ÿ”— Connect Local Repo to GitHub

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

git push

Sends your local commits to GitHub.


โฌ‡๏ธ Pull Changes

git pull

Fetches and merges changes from GitHub into your local branch.


๐Ÿ” Clone Then Push to New Repo

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

git mv old_name.txt new_name.txt

Git tracks this as a rename (rather than delete + add).


๐Ÿ—‘๏ธ Remove a File

git rm unwanted_file.txt

โœ… Commit and Push

git commit -m "Renamed and removed files"
git push

๐ŸŒฟ Branching & Merging

๐ŸŒฑ Create a New Branch

git branch feature-xyz

๐Ÿ”„ Switch to a Branch

git checkout feature-xyz

โž• Create & Switch in One Step

git checkout -b bugfix-login

๐Ÿ” Merge a Branch into Main

git checkout main
git merge feature-xyz

๐Ÿงน Delete a Merged Branch

git branch -d feature-xyz

๐Ÿงญ See All Branches

git branch        # local only
git branch -r     # remote only
git branch -a     # all

๐ŸŒ Push a Branch to GitHub

git push origin feature-xyz

๐Ÿ“ฆ Stashing & Cleaning

๐Ÿงณ Temporarily Save Changes (Stash)

git stash

Hides your uncommitted changes so you can switch branches safely.

๐ŸŽฏ Reapply Stashed Changes

git stash pop

๐Ÿงผ Remove Untracked Files

git clean -f

Deletes untracked files. Use with caution!


๐Ÿ•˜ Rewriting History

๐Ÿ”„ Amend Last Commit

git commit --amend

Edit the previous commit message or add forgotten changes.


๐Ÿšซ Undo a Commit (Soft Reset)

git reset --soft HEAD~1

Keeps changes but removes the commit.

๐Ÿ’ฅ Hard Reset to Last Commit

git reset --hard HEAD

โš ๏ธ WARNING: This erases all changes permanently.


๐Ÿ“œ Logs & Diffs

๐Ÿ“– View Commit History

git log
git log --oneline --graph --all

๐Ÿ” View File Differences

git diff                # unstaged vs working dir
git diff --staged       # staged vs last commit

๐Ÿท๏ธ Tags

๐Ÿ”– Create a Tag

git tag v1.0.0

๐Ÿš€ Push Tags to GitHub

git push origin v1.0.0

๐Ÿ“‹ List Tags

git tag

๐ŸŒฑ Rebasing & Cherry Picking

๐Ÿ”„ Rebase a Branch

git checkout feature
git rebase main

Rewrites your branch history on top of another branch.


๐Ÿ’ Cherry Pick a Commit

git cherry-pick <commit-hash>

Applies a specific commit to your current branch.


๐Ÿ“ฆ Git Submodules

โž• Add a Submodule

git submodule add https://github.com/user/repo.git path/to/module

๐Ÿ”„ Init & Update

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:

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

๐Ÿค 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

git clone https://github.com/yourusername/repo.git
cd repo

๐Ÿ”€ Add the Original Repository as "Upstream"

git remote add upstream https://github.com/original/repo.git

This helps you keep your fork updated with the original.


๐Ÿ”„ Sync Your Fork

git fetch upstream
git checkout main
git merge upstream/main

๐Ÿ“ค Create a Pull Request (PR)

  1. Push your changes to your forked repo:
    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:

<<<<<<< HEAD
your version
=======
their version
>>>>>>> branch-name

๐Ÿงฉ To Resolve:

  1. Edit the file to fix the conflict.
  2. Stage it again:
    git add conflicted_file
  3. Commit the resolution:
    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

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