Reputation: 11
I had cloned a repo after cutting a branch from the mainline and have now made changes to it. Now I want to push back my changes to the already existing remote branch I had cut. But on running 'git push' the code gets pushed to the master or the main branch and not the remote branch I had cut and cloned initially. How do I push my local code to a branch that already exists on git.
Upvotes: 1
Views: 3938
Reputation: 91
You can refer below commands :
git checkout -b <branch-name> -- locally create new branch
git push -u origin <branch-name> -- create/update branch on server
git checkout <branch-name> -- move head to branch so that changes can be done on that branch
git status -- check branch name & changes done
git branch -- show branch present in your local (fetched from server in your local)
Upvotes: 0
Reputation: 101
It is better to merge with the latest master from staging by :
git fetch origin master:branch_to_push
Checkout to it :
git checkout branch_to_push
Merge the working code:
git merge local_working_branch
Then, push this new branch over the one in staging:
git push origin branch_to_push:branch_present_on_staging
Hope this helps!
Upvotes: 2
Reputation: 6584
Try to specify the branch name explicitly:
git push origin name_of_your_branch:name_of_your_branch
That means that you specify the name of your local branch to be pushed, and the name of the remote branch where to push:
git push origin local-name:remote-name
Upvotes: 0
Reputation: 152
Try following,
Fetch branches
git fetch --all
See all available branches,
git branch
Checkout to the existing branch
git checkout BRANCH_NAME
Then try pushing
See this, https://www.atlassian.com/git/tutorials/using-branches/git-checkout
Upvotes: 1