Loading lessons...
Push to GitHub
Push to GitHub
git push sends your local commits to the remote repository.
The push command
git push
If your default remote and branch are set up (via -u earlier), this pushes to origin/main.
Push to a new branch
git push -u origin feature-login
This uploads the feature-login branch and sets it as your default for that branch.
What push does
git push copies the commits from your local branch to the matching remote branch. Your work now exists online, where others can see and pull it.
Push rejected?
If the remote has commits you do not have, Git refuses the push. Fix it by pulling first:
git pull
git push
Never push broken history
Pushing rewrites history for everyone. Never force push (--force) to shared branches unless you really know what you are doing.
TL;DR
git pushuploads local commits to the remote.git push -u origin branchsets the default remote branch.- Pull first if your push is rejected.
- Avoid force pushing to shared branches.