Sys-Admin

Git

Git is a distributed version control software system.

Configuration

Init

You initialized a fresh repo, but no remote exists yet, so Git can’t “set” it.

git init

Add the remote first.

git remote add origin https://github.com/<username>/<repo_name>.git # HTTPS
git remote add origin git@github.com:<username>/<repo_name>.git # SSH

Verify:

git remote -v

Github CLI

Login

gh auth login

Create repository

gh repo create airplane_mode --public --source=. --remote=origin --push

Add branch

git branch -m main

Commit + push

If you already have files:

git add .
git commit -m "Initial commit"
git push -u origin main

Remotes

list all Git remotes

git remote -v
git remote show origin # Detailed config

Set remote URL

Add local repo to existing repo on Github.

git remote set-url origin https://github.com/<username>/<repo_name>.git # HTTPS
git remote set-url origin git@github.com:<username>/<repo_name>.git # SSH

Overwrite remote main with your local work.

git push -f origin main

New branch from a commit

git log

Copy commit hash → e.g. abc1234.
Create and switch to a new branch starting at that commit:

git checkout -b new-feature abc1234

Reference

  1. Git wikipedea
  2. Git website