Use this when you want to save your local work with Git and upload it to GitHub.
1) Check what changed
git statusThis shows:
- modified files
- new files
- deleted files
2) Stage the files you want to include
To stage everything:
git add .To stage one file only:
git add path/to/fileTip: use git status again after staging so you can confirm exactly what will be committed.
3) Create a commit
git commit -m "Describe what you changed"A commit is a saved version of your project history.
Good commit message examples:
Fix typo in READMEAdd intro section to github guideUpdate animation script
4) Upload your commit to GitHub
git pushIf this is your first push on a new branch, Git may ask you to set the upstream branch. In that case, run the command Git suggests, usually:
git push -u origin <branch-name>Quick Version
git status
git add .
git commit -m "Describe what you changed"
git pushUseful Checks
See your recent commits:
git log --oneline -5See the exact changes before committing:
git diffSee staged changes only:
git diff --cachedCommon Problems
Nothing to commit
You may have forgotten to edit a file or stage it with git add.
Git says there is no upstream branch
Run:
git push -u origin <branch-name>You committed the wrong files
Check with:
git status
git diff --cachedThen adjust before creating the commit if needed.