Skip to content

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

License

Notifications You must be signed in to change notification settings

atharvbyadav/Git-GitHub

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

34 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ 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 "[email protected]"

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! πŸ’»πŸ”₯


About

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

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages