CodeNFacts
CodeHub
Home

All Categories


Sign In
Master git & github

Master Git & GitHub

Version control is the backbone of every real-world codebase. This guide walks through what Git and GitHub actually are, why every team relies on them, how Git works under the hood, and gives you practical commands, diagrams and a cheat sheet you can come back to any time.

~/codenfacts
$ git init
Initialized empty Git repository

$ git add .
$ git commit -m "first commit"
[main (root-commit) a1b2c3d] first commit

What is Git?

Git is a distributed version control system. It tracks every change made to your files over time, so you can see exactly what changed, when, and by whom — and roll back to any earlier point if something breaks. "Distributed" means every developer has a full copy of the project history on their own machine, not just on a central server.

Git was created by Linus Torvalds in 2005 to manage the Linux kernel's source code, and it has since become the default version control tool across almost every software team in the world.

Tracks history

Every commit is a snapshot you can return to

Enables teamwork

Multiple people can work on the same code safely

Works offline

Full history lives on your own machine

reference

Git & GitHub cheat sheet

The commands you'll reach for most often, grouped by task.

Setup & Config

  • git initInitialize a new repository
  • git clone <url>Copy a remote repo locally
  • git config --global user.name "Name"Set your name
  • git config --global user.email "you@mail.com"Set your email

Basic Workflow

  • git statusShow changed / staged files
  • git add <file>Stage a file
  • git add .Stage everything
  • git commit -m "message"Save a snapshot
  • git log --onelineView commit history
  • git diffShow unstaged changes

Branching & Merging

  • git branchList branches
  • git checkout -b <name>Create & switch to branch
  • git switch <name>Switch to existing branch
  • git merge <branch>Merge branch into current
  • git branch -d <name>Delete a merged branch

Remote & Collaboration

  • git remote add origin <url>Link a remote repo
  • git push -u origin mainPush & track upstream
  • git pullFetch + merge from remote
  • git fetchDownload changes without merging

Undo & Fix Mistakes

  • git restore <file>Discard unstaged changes
  • git reset --soft HEAD~1Undo last commit, keep changes
  • git revert <commit>Create a new commit that undoes one
  • git stashTemporarily shelve changes
  • git stash popRe-apply stashed changes

GitHub Specific

  • gh repo clone <owner/repo>Clone via GitHub CLI
  • gh pr createOpen a pull request
  • gh pr mergeMerge a pull request
  • gh issue listList repo issues

Git vs GitHub, at a glance

AspectGitGitHub
What it isA version control toolA cloud hosting platform for Git repos
Runs whereOn your local machineIn the cloud, accessed via browser/CLI
Needs internet?NoYes, for hosting & collaboration features
Core unitCommitRepository, Pull Request, Issue
CollaborationManual (patches, shared servers)Built-in: PRs, reviews, permissions
AlternativesMercurial, SVNGitLab, Bitbucket