Git & Github Beginner Routines Cheat Sheet

Table of Contents

πŸš€ Git & GitHub Beginner Routines Cheat Sheet

🟒 Routine 1: First-Time Setup

Step Command
Install tools sudo apt-get install git gh curl -y
Set username git config --global user.name "your_username"
Set email git config --global user.email "your_email@example.com"
Login to GitHub gh auth login
Follow prompts in terminal & browser

🟒 Routine 2: Cloning Repositories

Type Command
Public repo git clone https://github.com/username/repository.git
Private repo gh repo clone username/repository
List branches git branch -a
Switch branch git checkout branch-name

🟒 Routine 3: Adding a Remote to an Existing Project

Step Command
Add remote origin git remote add origin https://github.com/username/repository.git

🟒 Routine 4: Keeping Everything Up to Date

Method Command
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

Step Command
Create & switch branch git checkout -b my-feature
Stage changes git add .
Commit changes git commit -m "Describe what you did"

🟒 Routine 6: Updating Main & Merging Your Work

Step Command
Switch to main git checkout main
Pull latest changes
git pull –ff-only origin main
or
git pull –rebase origin main
Merge your branch git merge my-feature

🟒 Routine 7: Pushing Changes

Step Command
Push to GitHub git push

🟒 Routine 8: Resolving Conflicts

If you see conflict markers in a file:

<<<<<<< HEAD
Your changes
=======
Their changes
>>>>>>> main
Step Command
Edit file Remove conflict markers and keep the final version you want.
Stage resolved file git add filename
Continue rebase git rebase --continue
(Optional) Cancel rebase git rebase --abort

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


⭐ Quick Reference Table

Action Command Example
Install sudo apt-get install git gh curl -y
Configure git config --global user.name "your_username"
Clone Public git clone https://github.com/user/repo.git
Clone Private gh repo clone user/repo
Pull (fast-forward) git pull --ff-only origin main
Pull (rebase) git pull --rebase origin main
Create Branch git checkout -b branch-name
Switch Branch git checkout main
Stage Changes git add .
Commit git commit -m "message"
Merge Branch git merge branch-name
Push git push
Resolve Conflicts Edit + git add + git rebase --continue