Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can I do a get latest on a remote branch? [duplicate]

Tags:

git

git-branch

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?

like image 983
Pindakaas Avatar asked Dec 21 '14 10:12

Pindakaas


1 Answers

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

like image 73
Mohammad AbuShady Avatar answered Sep 28 '22 02:09

Mohammad AbuShady