0

I'm trying to set up branches so that when my employees first clone the repository they have all the branches available. This is how I want to set it up:

Have the Master branch that they don't and/or can't mess with. I'll be the one that syncs up working versions to that branch. Kind of like the final working version. But I want a development branch as a parent to development.username branch. They work in development.username (each will have a unique username) and they all sync their work to development. The development branch will later be synced up to Master branch.

What I'm having trouble doing is getting the branches to show up in SourceTree automatically so that they don't have to set them up. I'm trying to make it as easy as possible for them. Every time I clone the repository only the main branch is showing up, as main branch (whatever that branch was set to be; development, master, etc.) is the only active branch in GitBucket. I've worked under someone that set up SourceTree like this so I know it's possible. Unless I'm not remembering correctly.

How would I accomplish what I'm trying to do?

Hanxue
  • 12,243
  • 18
  • 88
  • 130

1 Answers1

0

When you clone a remote repository, a local copy of all the remote branches is available. In SourceTree, expand the remote's name, by default origin. You will see all the remote branches.

Git remote branches

The equivalent git command is

$ git checkout <remote-branchname>

Check Out All Remote Branches Locally

If your intention is to create a local branch for each of the remote branch, you can use this script.

function git_checkout_remote_branches() {
    # Track only the "origin" remote, or the remote name given
    remote=origin
    if [ $# -eq 1 ]; then
        remote=$1
    fi
    for branch in `git branch -a | grep remotes/$remote | grep -v HEAD | grep -v master `; do
       git branch --track ${branch#remotes/*/} $branch
    done
}
Hanxue
  • 12,243
  • 18
  • 88
  • 130