1

I'm using Github. My friend created a branch called broken_textures in our repository, and I cannot figure out how to switch to that branch. I've tried git pull origin/broken_textures and many variations of that, but it keeps telling me the repository does not exist. The most success I had was git checkout remotes/origin/broken_textures which created a detached HEAD pointing to the branch. I just want to copy the branch onto my computer so I can work on it, and later I want to merge it into master. How am I supposed to do this, and what am I not understanding about the branching system?

A. Kriegman
  • 510
  • 1
  • 4
  • 18
  • 2
    Are you both collaborates on the same repository and did he push his feature branch to origin? Can your friend checkout your branches? – tomerpacific Apr 17 '20 at 20:57
  • I'm not sure what those words mean, but we are using Github and both branches are listed on Github. Also when I run `git branch -a` in my terminal I see his branch listed as `remotes/origin/broken_textures`. I guess that means he did push his branch to origin, because I think origin means Github in this case. – A. Kriegman Apr 17 '20 at 21:07
  • What the output of `git branch -a` is? – 0andriy Apr 17 '20 at 21:31
  • do you have also trie with `git checkout --track origin/broken_textures` ? – SwissCodeMen Apr 17 '20 at 21:33
  • I just tried that and it seems to work, but I don't understand why I have to make a tracking branch instead of just fully switching to that branch. – A. Kriegman Apr 17 '20 at 21:47
  • The output of `git branch -a` is `* broken_textures`, `master`, `remotes/origin/HEAD -> origin/master`, `remotes/origin/broken_textures`, `remotes/origin/master`, where the local `broken_textures` branch was just created by @SwissCodeMen's suggestion. – A. Kriegman Apr 17 '20 at 21:48
  • Does this answer your question? [In Git, what is the difference between origin/master vs origin master?](https://stackoverflow.com/questions/18137175/in-git-what-is-the-difference-between-origin-master-vs-origin-master) – phd Apr 17 '20 at 22:33

2 Answers2

1

Checking out a local branch from a remote branch automatically creates what is called a “tracking branch” (or sometimes an “upstream branch”). Tracking branches are local branches that have a direct relationship to a remote branch. If you’re on a tracking branch and type git pull, Git automatically knows which server to fetch from and branch to merge into.

When you clone a repository, it generally automatically creates a master branch that tracks origin/master. However, you can set up other tracking branches if you wish – ones that track branches on other remotes, or don’t track the master branch. The simple case is the example you just saw, running git checkout -b [branch] [remotename]/[branch]. This is a common enough operation that git provides the --track shorthand:

$ git checkout --track origin/BRANCH_NAME

With --track you create a local branch. It depends on the git version whether you have to add --track or not (from Git 1.7.2.4 git checkout BRANCH_NAME is enough).

https://git-scm.com/book/en/v2/Git-Branching-Remote-Branches#_tracking_branches

SwissCodeMen
  • 4,222
  • 8
  • 24
  • 34
0

You are trying to access a branch which is not stored locally. So you have to fetch the details from the remote, create a local branch and it should be set to track the remote branch. The easiest way is to do the following

git fetch origin
git checkout -b broken_textures origin/broken_textures
Hrishi
  • 1,424
  • 1
  • 13
  • 29