Push Branch to GitHub
Push Branch to GitHub: Publishing Feature Work for Review
Pushing a local branch to GitHub shares your isolated feature commits with teammates, triggers CI checks, and lets you open a pull request. Until you run git push, your local branch exists only on your computer.
Publishing a Local Branch with Upstream Tracking
Suppose you created feature/header-nav, added assets/banner.svg, and committed your changes locally. Publish that branch to GitHub and save the upstream link with -u:
git switch feature/header-nav
git push -u origin feature/header-nav
GitHub creates the feature/header-nav branch on origin and prints a direct URL in your terminal so you can click straight to the Open a pull request form.
Pushing Follow-Up Commits
After pushing once with -u, push additional code-review fixes on the same branch with a short command:
git add styles.css
git commit -m "Refine mobile header padding in styles.css"
git push
Git knows which remote and branch to update from the tracking configuration saved earlier.
Deleting a Remote Branch After Merging
Once your pull request merges into main, delete the finished branch both remotely and locally so the repository stays tidy:
git push origin --delete feature/header-nav
git switch main
git branch -d feature/header-nav
Common Branch Pushing Mistakes
Typing git push origin main while sitting on feature/header-nav pushes main instead of your current feature branch. A safer habit is running git push -u origin HEAD, where HEAD always resolves to whatever local branch you currently have checked out.
Frequently Asked Questions
What does git push -u origin HEAD do?
HEAD tells Git to push your currently active local branch to a remote branch of the exact same name on origin, avoiding branch-name typos.
Why did Git reject my push with The current branch has no upstream branch?
You created the branch locally and ran bare git push without telling Git where to send it on origin. Run git push -u origin <branch-name> once to set the upstream link.
How do I rename a branch I already pushed to GitHub?
Rename it locally (git branch -m old-name new-name), push the new name (git push -u origin new-name), and delete the old remote branch (git push origin --delete old-name).
Unlock Your
Full Potential.
Sign in to track your learning journey, earn industry-recognized certificates, and join our elite developer community.
Quick Access With