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.
Quick reference
Section titled “Quick reference”git initgit branch -M maingit add .git commit -m "Initial commit"git remote add origin https://github.com/YOUR_USERNAME/YOUR_REPO.gitgit push --set-upstream origin mainOrient yourself first
Section titled “Orient yourself first”pwd # confirm you are in the right directoryls -la # list all files including hidden (e.g. existing .git)du -sh ./* # check size of each item before committingInit and branch
Section titled “Init and branch”git init # initialize repo in current directorygit branch -M main # rename default branch to maingit branch # confirm branch nameStage and commit
Section titled “Stage and commit”git status # see untracked filesgit add . # stage everythinggit status # confirm what is stagedgit commit -m "Initial commit"Connect remote and push
Section titled “Connect remote and push”git remote add origin https://github.com/YOUR_USERNAME/YOUR_REPO.gitgit remote -v # confirm remote URLgit push --set-upstream origin main # first push, sets tracking branchVerify
Section titled “Verify”git branch # confirm you are on maingit status # should say "nothing to commit, working tree clean"