Git & GitHub Cheat Sheet

A simplified, searchable guide for nocoders, beginners, and tech teams.

1 Setup & Connection

Clone Repository

clonedownload reponew computer
git clone https://github.com/user/repo.git
Downloads a full project from GitHub to your computer.

Connect Local Code to GitHub

connect repoadd originfirst push
git remote add origin URL git branch -M main git push -u origin main
Use this when you started locally and want to upload to a new empty GitHub repo.

Set Git User Identity

useremailauthor
git config --global user.name "Name" git config --global user.email "email@x.com"

Check Connected URL

remoterepo urlorigin
git remote -v
Shows which GitHub repository your folder is linked to.

Change Remote URL

change remoteupdate git url
git remote set-url origin NEW_URL
2 The Daily Workflow

Safe Rule for Beginners

saferulebest practice
git status
Pro Tip: Run this before any other Git action to avoid mistakes.

Check Git Status

statuscheck changesunstaged
git status
Check if files are changed, added, deleted, or ready to save.

Quick Daily Workflow

dailynormal flowsave code
When you want to upload changes
git status git add . git commit -m "message" git push origin main
Layman Meaning: Check changes → Select all → Save locally → Upload to GitHub.

Add Files to Git

addstageselect files
Add all files
git add .
Add specific file
git add src/pages/Home.jsx
Prepares your files to be saved in Git (staged).

Commit Code

commitsave versionsnapshot
git commit -m "updated homepage"
Creates a saved version of your code locally on your computer.

Push Code to GitHub

pushuploadpublish code
First push
git push origin main
Subsequent pushes
git push
Uploads your saved local commits to GitHub.
3 Syncing & Updating

Pull Latest Code

pulldownload latestsync
git pull origin main
Downloads the latest updates from GitHub and applies them locally.

Force Update Local Code

force updateoverwrite localmatch github
git fetch origin git reset --hard origin/main
Warning: Deletes your local uncommitted changes to match GitHub exactly.

Resolve Pull Conflict

conflictmergeboth modified
# 1. Find <<<<<<< markers in file # 2. Keep correct code, delete markers # 3. Save & run: git add . git commit -m "resolved conflict" git push origin main
4 Working With Branches

Check Current Branch

branchwhich branchmain
git branch
The branch with an asterisk (*) is the one you are currently using.

Switch Branch

switch branchcheckoutmove
git switch branch-name # or older command: git checkout branch-name

Create New Branch

new branchfeature branch
git switch -c new-branch-name
Creates a new branch and switches to it immediately.
5 Fixing Mistakes

Discard Local Changes

discardremove changesclean
Full clean reset
git reset --hard git clean -fd
Warning: Deletes all unsaved local work and untracked files.

Undo Last Commit (Keep Code)

undo commitkeep changesuncommit
git reset --soft HEAD~1
Removes the last commit from history, but keeps your code changes untouched.

Undo Last Commit (Delete Code)

delete last commithard undo
git reset --hard HEAD~1
Warning: Completely deletes the code changes from your last commit.

Stash Local Changes

stashtemporary savehide
git stash git pull origin main git stash pop
Temporarily hides local changes, updates from GitHub, and brings your changes back.
6 Extras

Fix LF/CRLF Warning

windowsline endingcrlf
git config --global core.autocrlf true
Fixes the common "LF will be replaced by CRLF" warning on Windows.

Most Common Git Commands

Action Command
Check changes git status
Add all changes git add .
Commit changes git commit -m "message"
Push to GitHub git push origin main
Pull from GitHub git pull origin main
Check GitHub URL git remote -v
Change GitHub URL git remote set-url origin URL
Check branch git branch
Switch branch git switch branch-name
Clone repo git clone URL
Force match GitHub git fetch origin + git reset --hard origin/main

Frequently Asked Questions

Git & GitHub Basics

What is the difference between Git and GitHub?

Git is the underlying tool installed on your computer that tracks changes to your files. GitHub is an online service where you host those tracked files so you can share them with others and collaborate.

Do I need to install Git separately?

Yes. Git is a piece of software that must be installed on your computer. GitHub is just a website. You can download Git from git-scm.com.

How do I check if Git is installed?

Open your terminal and run git --version. If it returns a version number (like git version 2.39.0), it is installed successfully.

What is a repository (repo)?

A repository is simply a folder that Git is actively tracking. It contains all your project files and a hidden .git folder that stores the history of every change ever made.

GitHub Account & Repository Setup

Should I create the repository first on GitHub or locally?

For beginners, it's easier to create the repository on GitHub first (so it creates the initial files), and then use git clone to download it to your computer. If you already have code on your computer, use git init then git remote add origin to connect it.

Should my repository be Public or Private?

Public: Anyone on the internet can see your code. Great for portfolios and open source.
Private: Only you and people you explicitly invite can see the code. Best for client work and proprietary projects.

What should I name my repository?

Use simple, descriptive names in lowercase with hyphens for spaces. For example: my-portfolio-website or crm-dashboard.

What is README.md?

It is a Markdown text file that serves as the "homepage" of your repository. When someone visits your GitHub repo, this is the first thing they read to understand what the project does.

Uploading Code to GitHub

How do I connect git to my code and upload it?

If you have an existing local folder, follow these steps to connect and upload:


1. git init (Initialize git)

2. git add . (Stage files)

3. git commit -m "first commit" (Save locally)

4. git remote add origin https://github.com/... (Link to GitHub)

5. git push -u origin main (Upload)

What does `git init` do?

It creates a hidden .git folder in your current directory. This turns a normal folder into a Git repository, allowing Git to start tracking your files.

What does `git add .` do?

It "stages" all modified and new files. This tells Git: "Get these files ready, I want to include them in my next save."

What is a commit?

A commit is a permanent snapshot of your code at a specific point in time. It acts like a save point in a video game that you can always return to.

Why are commit messages important?

They act as a log of what was changed and why. Instead of vague messages like "updated stuff", use clear messages like "fixed login button bug" so your team understands the history.

Authentication & Access

Why is GitHub asking for a token instead of a password?

GitHub removed password authentication for security reasons. You must generate a Personal Access Token (PAT) in your GitHub Settings (Developer Settings) and use that token as your password in the terminal.

What is SSH vs HTTPS?

Both are methods to securely connect to GitHub.
HTTPS: Easier to set up, but requires entering your token periodically.
SSH: Requires generating a cryptographic key on your computer once, but you will never have to type a password/token again.

How do I connect VS Code with GitHub?

Open the "Source Control" tab on the left sidebar (it looks like a branching node). Click "Publish to GitHub" or "Initialize Repository". VS Code will prompt you to log into GitHub through your browser automatically.

Common Errors Beginners Face

Why is `git push` failing?

This usually happens when someone else uploaded changes to GitHub that you don't have on your computer yet. Run git pull origin main first to download their changes, fix any conflicts, and then try git push again.

What does “remote origin already exists” mean?

You tried to run git remote add origin, but your computer is already connected to a GitHub URL. If you want to change the URL, use git remote set-url origin NEW_URL instead.

Why are my files not appearing on GitHub?

Saving files on your computer does not automatically send them to GitHub. You must complete the full cycle: git add .git commit -m "..."git push origin main.

Why is `.gitignore` important?

It's a text file where you list files or folders that Git should completely ignore (like node_modules, passwords, or massive databases). This prevents you from accidentally uploading junk or sensitive data to the internet.