Create a new repository on GitHub & push local repo (common workflow)
1) Create repository on GitHub (via website)
- On GitHub, click + → New repository.
- Give it a Repository name (e.g.,
my-first-repo
), add optional description, choose Public/Private, then click Create repository.
2) Create & push a local repo (commands)
# inside your project folder
git init
git add .
git commit -m "Initial commit"
# connect to GitHub remote (example using HTTPS)
git remote add origin https://github.com/YOUR_USERNAME/my-first-repo.git
# push the local 'main' branch up to GitHub (create remote branch)
git branch -M main
git push -u origin main
If you use SSH, create an SSH key and add the public key to GitHub settings, then use the SSH remote url instead (git@github.com:...).
Common Git Commands (cheatsheet)
Staging & commits
git status
git add
git add .
git commit -m "Message"
git commit --amend
Branches & remotes
git branch
git branch -M main
git checkout -b feature/xyz
git merge main
git remote -v
git push origin branch-name
git pull origin main
Other helpful commands
git log --oneline
git diff
git revert
git reset --hard # be careful - can discard changes
Simple Git Workflow (recommended for beginners)
- Clone repository:
git clone <repo-url>
- Create a branch:
git checkout -b feature/your-feature
- Make changes & commit often:
git add .
→git commit -m "msg"
- Push branch:
git push origin feature/your-feature
- Create a Pull Request on GitHub to merge your branch into
main