Skip to content

Git Init and First Push

This document provides a standard initial git setup when starting a project locally and later pushing to remote repository instead of starting from a pull operation.

Terminal window
git init
git branch -M main
git add .
git commit -m "Initial commit"
git remote add origin https://github.com/YOUR_USERNAME/YOUR_REPO.git
git push --set-upstream origin main
Terminal window
pwd # confirm you are in the right directory
ls -la # list all files including hidden (e.g. existing .git)
du -sh ./* # check size of each item before committing
Terminal window
git init # initialize repo in current directory
git branch -M main # rename default branch to main
git branch # confirm branch name
Terminal window
git status # see untracked files
git add . # stage everything
git status # confirm what is staged
git commit -m "Initial commit"
Terminal window
git remote add origin https://github.com/YOUR_USERNAME/YOUR_REPO.git
git remote -v # confirm remote URL
git push --set-upstream origin main # first push, sets tracking branch
Terminal window
git branch # confirm you are on main
git status # should say "nothing to commit, working tree clean"