Git — starter
Starter First day on a project.New repo (local first)
bash
mkdir my-project && cd my-project
git init
git branch -M main
# first files
echo "# my-project" > README.md
git add README.md
git commit -m "chore: initial commit"Connect to GitHub / remote
bash
# create empty repo on GitHub first, then:
git remote add origin [email protected]:YOU/my-project.git
git push -u origin mainHTTPS alternative:
bash
git remote add origin https://github.com/YOU/my-project.gitClone existing
bash
git clone [email protected]:org/repo.git
cd repoShallow (CI / huge history you don’t need):
bash
git clone --depth 1 [email protected]:org/repo.gitSee state
bash
git status
git status -sb # short + branch
git log --oneline -10
git remote -vCreate a branch (feature work)
bash
git switch -c feature/login-form
# older alias still works:
# git checkout -b feature/login-formStage & commit
bash
git add path/to/file
git add -p # patch mode — stage hunks
git commit -m "feat: add login form"
# amend last commit (only if NOT pushed, or you know the cost)
git commit --amend --no-editConfig once per machine
bash
git config --global user.name "Your Name"
git config --global user.email "[email protected]"
git config --global init.defaultBranch main
git config --global pull.rebase false # or true if you prefer rebase pulls
git config --global core.editor "code --wait"Cheat: “is this a git repo?”
bash
git rev-parse --is-inside-work-tree