GitHub Basics CheatSheet

Basic GitHub commands for solo developers

Download as .pdf

API: /api/v1/cheatsheet/github-basics-cheatsheet

Git / GitHub Cheat Sheet

Check where you are

Before doing Git commands, make sure you are inside the correct project folder:

bash

1
pwd

List files:

bash

1
ls

Check Git status:

bash

1
git status

If you see:

bash

1
fatal: not a git repository

you are either in the wrong folder or you have not run git init yet.

Initialize a local Git repo

Use this when your project folder is not yet a Git repo.

bash

1
git init

Set the branch name to main:

bash

1
git branch -M main

Check status:

bash

1
git status

Add a .gitignore

Create a file called:

.gitignore

Important: .gitignore should be in the repo root, for example:

my-repo/
├── .git/
├── .gitignore
├── module_1/
├── module_2/
└── module_3/

For Python projects, use something like:

text

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# Python cache
__pycache__/
*.py[cod]

# Virtual environments
venv/
.venv/
env/

# Environment variables / secrets
.env
.env.*

# VS Code
.vscode/

# Build files
build/
dist/
*.egg-info/

# Testing / coverage
.pytest_cache/
.coverage
htmlcov/

# OS files
.DS_Store
Thumbs.db

First upload to GitHub

When you are uploading the project for the first time:

1: Stage files

bash

1
git add .

Step 2: Commit files

bash

1
git commit -m "Initial commit"

Step 3: Connect to GitHub repo

Use your own GitHub repo URL:

bash

1
git remote add origin https://github.com/YOUR-USERNAME/YOUR-REPO.git

Step 4: Push to GitHub

bash

1
git push -u origin main

After this, refresh GitHub. Your files should appear.

Normal update workflow

Use this after you add, edit, rename, or delete files.

bash

1
2
3
4
git status
git add .
git commit -m "Describe what changed"
git push

For one specific file:

bash

1
2
3
git add module_1/app.py
git commit -m "Update app routes"
git push

Pull changes from GitHub

Run this when GitHub has changes that your local machine does not have:

bash

1
git pull

Or explicitly:

bash

1
git pull origin main

Use pull before starting work if you use multiple computers or edit files on GitHub directly.

Fix “fetch first” error

Error:

bash

1
! [rejected] main -> main (fetch first)

This means GitHub has commits that your local repo does not have.

Try:

bash

1
2
3
4
5
6
7
8
9
git pull origin main
git push
bash

If it says the histories are unrelated, use:

```bash
git pull origin main --allow-unrelated-histories
git push

Check your remote GitHub repo

Show connected GitHub repo:

bash

1
git remote -v

Expected output:

bash

1
2
origin  https://github.com/YOUR-USERNAME/YOUR-REPO.git (fetch)
origin  https://github.com/YOUR-USERNAME/YOUR-REPO.git (push)

Change the remote URL:

bash

1
git remote set-url origin https://github.com/YOUR-USERNAME/YOUR-NEW-REPO.git

Remove the remote:

bash

1
git remote remove origin

Branch basics

Show branches:

bash

1
git branch

Create a new branch:

bash

1
git checkout -b branch-name

Switch branches:

bash

1
git checkout main

Modern equivalent:

bash

1
git switch main

Rename current branch to main:

bash

1
git branch -M main

Delete a local branch:

bash

1
git branch -D branch-name

Push a new branch to GitHub:

bash

1
git push -u origin branch-name

Remove files from Git tracking but keep them locally

Useful if you accidentally added venv/, .env, or pycache/.

bash

1
2
3
git rm -r --cached venv
git rm -r --cached __pycache__
git rm --cached .env

Then commit:

bash

1
2
git commit -m "Remove ignored files from tracking"
git push

If you already updated .gitignore, you can also do:

bash

1
2
3
4
git rm -r --cached .
git add .
git commit -m "Apply gitignore rules"
git push

Authentication with GitHub

GitHub does not accept your account password for Git pushes over HTTPS.

When asked for credentials:

  • Username: your GitHub username
  • Password: your GitHub personal access token

Join the Newsletter

Practical insights on Django, backend systems, deployment, architecture, and real-world development — delivered without noise.

Get updates when new guides, learning paths, cheat sheets, and field notes are published.

No spam. Unsubscribe anytime.



There is no third-party involved so don't worry - we won't share your details with anyone.