Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Development Tools Git Basics Working With Remote Repositories GitHub

Martin Aasen
Martin Aasen
9,067 Points

Working with remote branches

Hello

So we have a small project we are working on using Github.

This is how we want it to work:

We have one main branch "master", that on a day to day basis is untouched. We also have two branches from "master" named "web" and "sever".

The way we want to work is that when people want to add a feature to either the server or the web, they create a branch from that main "web" or "server" branch, do their work, and then push/merge that to the "web" or "server" branch depending on where they originally branched out. Then at weekly meetings, or whenever needed, we will merge the two main branches, web and server, into the master branch.

This is a very wide question but how would we set up these branches and push / pull changes from all the users. I have tried googling it but we just can't make it work right. Our main problem being that if i for example create a branch, even the first main web branch from master, and push as i normally do, the other people working on the project can't access these branches. Their client simply tells them there are no updates and that that branch does not exist.

So obviously there is something wrong with the way we are setting up these branches but i have read every article i can find on the matter but i simply can't make it work.

Any examples of how we would set it up or links to articles that explains it would be greatly appreciated.

Thanks in advance!

2 Answers

Hey Martin,

What you're explaining sounds to me like you are making local "feature" branches, they will show up in your git client and you will be able to push / pull from them but no one else will be able to see them since they are not originating on the remote server (or in your case github). There are several ways to handle the creating of remote branches.

  1. You can log into git hub directly and create a new branch, name it what you'd like and then your client should be able to recognize there is a new branch. If for some reason your git client does not recognize there is a new branch (it will need to say checkout remote branch branch name) and does not allow you switch to it then you need to fetch the new branches. You will need to navigate to your project folder / git repo via terminal or CMD Line, and use the following command git fetch origin.
  2. You could also be ninja-like and do everything via command line, navigate to your local project folder / git repo and run git fetch origin then confirm the new branch is there with git branch, to checkout the new branch type **git checkout [name of new branch].

It would also be helpful to know what git client you're using and on what OS.

Links to some helpful stuff...

  1. Git Branching - Remote Branches
  2. Git Checkout Remote Branch
Martin Aasen
Martin Aasen
9,067 Points

Thanks allot for your reply. It turned out all i had to do was git fetch origin, but with specified what branches i wanted to have locally. git fetch origin did not work but i think i ended up using git fetch origin/web web , or something like that. Because the new branches showed up in git branch -a , but they were listed as myrepository/origin/web or something like that.