2

I created a new branch in git from my local system using the command:

git checkout -b branchname

My doubt is whether other users from their system will be able to switch to this new branch? Or do I need to push the changes to the server, then only they can also access it?

-- Thanks

Ivin
  • 4,435
  • 8
  • 46
  • 65

1 Answers1

4

You need to push the branch for them to be able to fetch it.

Even if those users have a direct access to your repo and have added it as a remote, they would still need to fetch your repo in order to realize that you have created a branch.

So the act alone of creating a branch isn't enough to notify anybody.
They need to fetch, or you need at least to push to a repo from which they can fetch.


The OP goose asks in the comments:

Say if someone uses the command: git checkout my-new-branch, will they get the set of changes?

No. They would simply create a branch in their own local git repo.

The documentation on Git branch has a funny expression in the top left corner:

Git --everything-is-local

Everything is local.

it should be as follows: git checkout -b new-branch AND git push Is it?

You don't have to push until you are ready.
Creating the branch alone wouldn't be very interesting for others.
Wait until have have made some commits before pushing it.

But the first time you will push said new branch, set its upstream branch immediatly:

git push -u origin myNewBranch

See "Git: Why do I need to do --set-upstream all the time?".

You only have to do once.
After that, when you want to push again (because you have made additional commits you want to be visible, a simple git push will be enough.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I dont want to push this branch to common repo, at least for now; need to make some changes before pushing. Say if someone uses the command: git checkout my-new-branch, will they get the set of changes? – Ivin Feb 21 '13 at 07:18
  • Maybe you should make a new repo only for your dedicated users. – Raptor Feb 21 '13 at 07:19
  • @goose no, they won't see any change or any new branch until you are pushing something. If they do a `git checkout my-new-branch`, all they are doing is creating a branch named like yours on their own local repo. – VonC Feb 21 '13 at 07:22
  • @goose as the documentation about branch mentions (top left corner of http://git-scm.com/book/en/Git-Branching-Remote-Branches): "git --everything-is-local" ;) What you are doing remains local until pushed. – VonC Feb 21 '13 at 07:24
  • Ok, it should be as follows: git checkout -b new-branch AND git push Is it? – Ivin Feb 21 '13 at 07:27
  • @goose ... and push it when you want the commits you have made in them visible (fetched) by others. But creating the branch alone does not warrant a push. Creating the branch, making commits, fixes, cleanup, ... and *then* pushing the branch is ok. – VonC Feb 21 '13 at 07:33
  • @goose don't forget, on your first push, to set the upstream branch: http://stackoverflow.com/questions/6089294/git-why-do-i-need-to-do-set-upstream-all-the-time : `git push -u origin myNewBranch`. You do that only once. After that, a simple `git push` is enough to update your upstream branch with new commits done on your local branch. – VonC Feb 21 '13 at 07:34