Ashutosh Ashutosh - 1 month ago 19
Git Question

git pull merging one branch into current branch

I'm a bit confused here.

I created a repository with two developers.

First developer created a new branch mysql_login and pushed a file.

Other developer created a new branch mysql_register and pushed a file.

Now my questions:


  1. Is it possible to pull another branch so that git branch command displays:

    master

    mysql_login

    mysql_register



My second developer was on branch mysql_register and executed the command:

git pull origin mysql_login


This command pulled files from branch mysql_login and merged into mysql_register


  1. Is it possible to prevent second developer from pulling or pushing to branch mysql_login?



Like I can prevent users to access/pull/fetch other branches.

I hope I am clear with my questions

Thanks

Answer

Is it possible to pull another branch (...):

Use fetch and checkout commands to that. git fetch will update repository status from remote and git checkout <branchname> will create a local copy of remote branch resulting in branch list you need

Is it possible to prevent second developer from pulling or pushing to branch mysql_login?

You can set branch restrictions with bitbucket, but I believe your problem can be solved with correct git usage - have non-shared user feature branches and have one developer merge progress into common codebase.

Your second developer should also do fetch and checkout another branch to prevent unwanted branch merges.

See for example a simple git branching model.

Comments