newwebdev
newwebdev

Reputation: 427

How to create and share a git branch with other developers?

How can I create a new branch and push it to the remote and then share it with the other developers? I'm following the below steps. What's wrong, missing?

Developer A creates the following:

git branch myBranch
git push origin myBranch

Then the remote should be updated:

git remote update

Developer B and C create the same branch on their locals:

git checkout --track origin/myBranch

Then what? If the above steps are correct, then how should I configure the new branch? What should be the correct order of steps to follow for this problem?

Upvotes: 2

Views: 17074

Answers (2)

mateor
mateor

Reputation: 1369

Looks like you are skipping the fetch from Developers B and C. If your shared project's repository is $ORIGIN and the branch you want to share is $MYNEWBRANCH

Developer A

 git checkout -b $MYNEWBRANCH # then make changes
 git add $FILES
 git commit
 git push $ORIGIN $MYNEWBRANCH

Developer B/C (if they have already cloned the repo earlier before your new branch was created):

git fetch origin
git checkout -t $MYBRANCH

Whenever Dev B and C want the latest changes, they can git pull, which is really just git fetch and git merge combined.

Upvotes: 1

leifericf
leifericf

Reputation: 2372

First, create and checkout your new branch locally:

git checkout -b myBranch

Then push your new branch to the remote:

git push -u origin myBranch

Now your friends can check it out:

git checkout myBranch

Have a look at the documentation for checkout and push for more details and options.

Upvotes: 1

Related Questions