Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to push changes to master branch while in another branch

Tags:

git

git-branch

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...

like image 477
Nithin P.H Avatar asked Aug 20 '18 10:08

Nithin P.H


3 Answers

 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

like image 91
XX 吕 Avatar answered Nov 13 '22 15:11

XX 吕


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.

like image 24
wotanii Avatar answered Nov 13 '22 16:11

wotanii


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**
like image 34
sachin_ur Avatar answered Nov 13 '22 14:11

sachin_ur