Git & Github Beginner Routines Cheat Sheet

Table of Contents

🚀 Git & GitHub Beginner Routines Cheat Sheet

🟢 Routine 1: First-Time Setup

StepCommand
Install toolssudo apt-get install git gh curl -y
Set usernamegit config --global user.name "your_username"
Set emailgit config --global user.email "your_email@example.com"
Login to GitHubgh auth login
Follow prompts in terminal & browser

🟢 Routine 2: Cloning Repositories

TypeCommand
Public repogit clone https://github.com/username/repository.git
Private repogh repo clone username/repository
List branchesgit branch -a
Switch branchgit checkout branch-name

🟢 Routine 3: Adding a Remote to an Existing Project

StepCommand
Add remote origingit remote add origin https://github.com/username/repository.git

🟢 Routine 4: Keeping Everything Up to Date

MethodCommand
Fast-forward only
git checkout main\ngit pull –ff-only origin main
Rebase (linear history)
git checkout main\ngit pull –rebase origin main

🟢 Routine 5: Creating & Working on a Branch

StepCommand
Create & switch branchgit checkout -b my-feature
Stage changesgit add .
Commit changesgit commit -m "Describe what you did"

🟢 Routine 6: Updating Main & Merging Your Work

StepCommand
Switch to maingit checkout main
Pull latest changes
git pull –ff-only origin main
or
git pull –rebase origin main
Merge your branchgit merge my-feature

🟢 Routine 7: Pushing Changes

StepCommand
Push to GitHubgit push

🟢 Routine 8: Resolving Conflicts

If you see conflict markers in a file:

<<<<<<< HEAD
Your changes
=======
Their changes
>>>>>>> main
StepCommand
Edit fileRemove conflict markers and keep the final version you want.
Stage resolved filegit add filename
Continue rebasegit rebase --continue
(Optional) Cancel rebasegit rebase --abort

Tip: Run git status often to see what has changed.


⭐ Quick Reference Table

ActionCommand Example
Installsudo apt-get install git gh curl -y
Configuregit config --global user.name "your_username"
Clone Publicgit clone https://github.com/user/repo.git
Clone Privategh repo clone user/repo
Pull (fast-forward)git pull --ff-only origin main
Pull (rebase)git pull --rebase origin main
Create Branchgit checkout -b branch-name
Switch Branchgit checkout main
Stage Changesgit add .
Commitgit commit -m "message"
Merge Branchgit merge branch-name
Pushgit push
Resolve ConflictsEdit + git add + git rebase --continue