While we are working in different branches in git repo is it possible to accidentally push your changes from a branch say demo to master. I do know in order to bring the changes to master branch we have to do a merge the require branch to the master.
Sometimes when I push to a branch I have these doubt if I'll push it to master accidentally so just to clear that up...
git push origin local-branch-name:remote-branch-name
In this case, it should be:
git push origin demo:master
If you're using gitlab/github, you can set master
branch as protected
to avoid pushing some branch to master accidentally
git push origin master
This pushes any branch you are on to the master branch in the origin repository.
the shortcut
git push
only works, if the current branch is linked to some remote branch via --set-upstream
. For example with
git push --set-upstream origin master
Note: There are more ways to set an upstream branch
It is perfectly possible to accidentally push to a wrong branch. For example when you were tracking a wrong branch, or because there was a typo in the push-command, or because you forgot what branch you were on.
No need to worry
Because if you are in other branch you made changes and unfortunately pushed to master
Ex: Your in slave branch you pushed to master (git push orgin master
)
It will show Everything up-to-date
If you push recursively also (git push -u origin master
) master branch won't affect (If you are in other branch only)
Master branch wont change until unless you merge with other branch's or till changes made in master
**cool**
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With