Using git and GitHub


Beginner workflow (Git + GitHub + PowerShell + gh)

Summary: the beginner-friendly stance

  • No rebase
  • git sync when starting/resuming work and after PR merges
  • Commit and push checkpoints as you go
  • Merge to main via PR + squash merge using gh (CLI)


0) One rule

  • Keep main clean.
  • Do your work on a branch.
  • Merge via PR (squash) so main stays simple and “green”.


0.1) Once per machine.

Install git & GitHub CLI and authenticate
winget install --id Git.Git -e --source winget
winget install --id GitHub.cli -e

gh auth login

git config --global alias.sync "fetch --prune"
git config --global fetch.prune true
git config --global pull.ff only
git config --global alias.lg "log --oneline --decorate --graph -20"
git config --global alias.br "branch --show-current"


A) Sync local repo (when starting/resuming work or when you have changes from GitHub)

git switch main
git sync
git merge --ff-only origin/main

If the last line fails, stop and inspect:
git status
git lg

(You should not “force it”. Decide intentionally.)


B) Start a coding branch (even if you already edited files)

$branch="fix/readme-typos"

git status
git switch -c $branch

If the branch already exists:
git switch $branch


C) Checkpoints while coding (save + upload)

1st checkpoint (first push sets upstream)

git status
git add -A
git commit
git push -u origin $branch

Next checkpoints

git add -A
git commit
git push

If git push is rejected (rare for you)

This means “remote has commits you don’t have”.

Beginner-safe fix (no rebase):
git fetch --prune
git merge --no-edit '@{u}'
git push

If the merge conflicts: resolve, commit, push.


D) Open PR + squash-merge via CLI (no website)

Create the PR

From your feature branch:
gh pr create --base main --fill

  • --base main targets main
  • --fill uses commit(s) to populate title/body ([GitHub CLI][2])

Merge it (squash) and delete the branch

When you don’t use auto-merge / checks:
gh pr merge --squash --delete-branch

If your repo requires checks and you want it to merge when ready:

```powershell
gh pr merge --auto --squash --delete-branch
```
Flags are official: --squash, --delete-branch, --auto. ([GitHub CLI][3])

Sync local main after merge (NOT always needed)

git switch main
git sync
git merge --ff-only origin/main

Cleanup local branch

If gh pr merge --delete-branch didn’t remove your local branch (it can vary by setup), delete it explicitly:
git branch -d $branch


E) “I’m mid-branch but main advanced (Codex PR merged)”

Update your branch explicitly (no rebase):
git switch $branch
git sync
git merge origin/main

Then continue work, test, push, and (later) PR + squash merge again.

temporarily relax “PR always” for tiny fixes.

F) I want to quickly fix a typo, without Pull Requests and churn

git switch main; git sync; git merge --ff-only origin/main
# edit typo
git add -A; git commit; git push


Start a brand new project from the CLI

Two common cases.

1) Create a new repo on GitHub + clone it

$repo="my-new-project"
gh repo create $repo --private --clone
cd $repo

gh repo create supports --private/--public and --clone. ([GitHub CLI][1])

Then add your initial files:
ni README.md
git add -A
git commit -m "Initial commit"
git push -u origin main

2) You already have a local folder and want to publish it to GitHub

From inside your project directory:
git init
git add -A
git commit -m "Initial commit"
gh repo create --source=. --private --push

  • --source.= creates the GitHub repo from the current directory
  • --push pushes your initial commit(s) ([GitHub CLI][1])

[1]: https://cli.github.com/manual/gh_repo_create [2]: https://cli.github.com/manual/gh_pr_create [3]: https://cli.github.com/manual/gh_pr_merge
Topic revision: r10 - 03 May 2026, NickDemou
Copyright © enLogic