11

I am trying to catchup with the latest code from a remote github branch. Suppose this branch is called myDevBranch how can I get this locally? I tried:

git fetch myDevBranch 

This returns :

fatal: 'myDevBranch' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

Looks like a securuty issue or is there another way of getting the remote branch locally?

love
  • 1,000
  • 2
  • 16
  • 35
Pindakaas
  • 4,389
  • 16
  • 48
  • 83
  • 1
    **Hint:** `'myDevBranch' does not appear to be a git repository`. Read up about how `git fetch` is called: http://git-scm.com/docs/git-fetch – MBlanc Dec 21 '14 at 10:12

1 Answers1

17

You don't fetch a branch, you fetch a remote, so the correct line would be

git fetch origin # or whatever your remote is called

Then the all tracking branches are updated, your updated code will be it a branch called origin/myDevBranch, again origin is replaced with your upstream name

To update your local branch you can merge the upstream git merge origin/myDevBranch but you need to make sure that your HEAD is pointing to your local branch of this remote (aka myDevBranch),

Or you can checkout to it git checkout origin/myDevBranch but that would leave you in a detached head mode, you can create a new local branch from that remote using git checkout -b

If your HEAD is pointing to your current branch, then you can do a git pull, keep in mind that pull will do both fetch and merge, and if your branch has diverged for any reason you would get a conflict that you will need to resolve by your self.

If you need to rebase then you could either do a manual fetch and rebase or you could do a git pull --rebase

Mohammad AbuShady
  • 40,884
  • 11
  • 78
  • 89
  • 2
    you can also use `git pull` to get the whatever is there in the remote branch in your computer. It _Incorporates changes from a remote repository into the current branch. In its default mode, `git pull` is shorthand for `git fetch` followed by git `merge FETCH_HEAD`._ Source: [https://git-scm.com/docs/git-pull] – Paramvir Singh Karwal Jun 04 '18 at 05:21
  • Thanks @ParamvirSinghKarwal, you're correct indeed, I'll update my answer – Mohammad AbuShady Jun 04 '18 at 09:01
  • You can also use ```git fetch -vp``` to show the verbose progress, ie what branches are up to date and what has been updated – aabiro Jul 26 '18 at 08:19