
Push Branch To Github in Git
π How to Push a Branch to GitHub
When working with Git, you often need to push your local changes to GitHub so others can see or collaborate on your work. Hereβs how to push a branch to GitHub.
π Steps to Push a Branch to GitHub
1οΈβ£ Check Your Current Branch
Before pushing, ensure you're on the correct branch:
git branch
If needed, switch to your branch:
git checkout feature-branch
2οΈβ£ Add and Commit Changes
Make sure your changes are staged and committed:
git add .git commit -m "Added new feature"
3οΈβ£ Push the Branch to GitHub
β If the branch already exists on GitHub:
git push origin feature-branch
β If the branch is new and doesnβt exist on GitHub:
Use the -u
flag to track it:
git push -u origin feature-branch
Now, future pushes can be done with just:
git push
4οΈβ£ Verify the Push on GitHub
- Go to your repository on GitHub.
- Click on the "Branches" tab to see your branch.
π₯ Example Workflow
git checkout -b new-featuregit add .git commit -m "Implemented new feature"git push -u origin new-feature
π― Summary
β
Check your branch β git branch
β
Add & commit changes β git add . && git commit -m "msg"
β
Push to GitHub β git push origin branch-name
β
Use -u
for new branches β git push -u origin branch-name