0

my local and remote branches

Hello, the problem: when I type "git branch -a" i can see the branch I need colored in red -

remotes/origin/ANL

in the remote repository on Github I can see this branch and the fact that a commit was done 3 days ago to this branch,

I need it to be also a local branch, how to do it?

Please help me. tried to do git fetch origin,git remote update those don't make the ANL branch to appear locally..

3 Answers3

2

Under normal circumstances you just say

git checkout ANL

That won't work if multiple remotes have branches with that name, but if you just have one remote this is the simplest way. Other solutions (as suggested by EncryptedWatermelon) are unnecessarily complex and won't result in remote tracking being as you'd expect. (Which is why you should always be suspicious of anyone who pressures you to accept their answer, but I digress...)


Update: Since EncryptedWatermelon has chosen to continue spreading misinformation instead of actually testing these commands and educating themselves, here's actual commands and output to demonstrate how this works.

First the output of fetch shows that the name we are using matches a remote branch:

$ git fetch
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 2 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (2/2), 207 bytes | 2.00 KiB/s, done.
From C:/Users/Mark/toy
 * [new branch]      x          -> origin/x

And now here's how to create the local branch and check it out:

$ git checkout x
Switched to a new branch 'x'
Branch 'x' set up to track remote branch 'x' from 'origin'

And afterward, here's the log, so you can see that indeed we are properly positioned at the remote branch:

$ git log --oneline
38018c6 (HEAD -> x, origin/x) 2
f9ff458 (origin/master, origin/HEAD, master) 1
Mark Adelsberger
  • 42,148
  • 4
  • 35
  • 52
1

To make a local branch of a remote branch do git branch ANL origin/ANL or to create the branch and switch to it git checkout -b ANL origin/ANL

EncryptedWatermelon
  • 4,788
  • 1
  • 12
  • 28
-1

You can check the remote url by command git remote -v, make sure you are using the correct remote.
If the url is correct, then you can check the remote branch exists or not
How to check if remote branch exists on a given remote repository?

Chuck Lu
  • 173
  • 12