I'm having problems on fetching one specific branch from my remote repo.
If I do git branch -a the output is:
* master
remotes/origin/HEAD -> origin/master
remotes/origin/master
remotes/origin/release/2.0.23175_BBDDv10
...
and that is ok, all my branches are in remote but as soon as I do
git fetch origin/release/2.0.23175_BBDDv10
I receive:
fatal: 'origin/release/2.0.23175_BBDDv10' 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.
I'm the owner of the repo and I have rights on it and if I do:
git remote -v
the output is:
origin https://xxxm@xxx.org/xxxxx/xxxxxxx.git (fetch)
origin https://xxx@xxx.org/xxxxx/xxxxxxx.git (push)
So 'origin' is pointing to where it have to.
At this point I'm stuck on being able to fetch one specific branch (haven't tried fetch --all yet)
Something to add just in case:
Not sure it may have something to do with it, but just in case and if it is of any help, I can add that I pushed two very big files by mistake yesterday and then removed them both following 'BFG Repo Cleaner' instructions (https://rtyley.github.io/bfg-repo-cleaner/). They're easy to follow and my big unwanted files dissapeared from local and remote/history.
The git fetch
command takes zero, one, or two-or-more arguments:
git fetch
: call up the default remote (usually origin
) and fetch everythinggit fetch remote
: call up the named remote. Usually you must use origin
here.git fetch remote branch1 ... branchN
: call up the named remote, and when it lists its branches, pick out only the specific named branches.You're trying to use the last of these three forms but making two separate mistakes:
origin
.origin/*
names in your Git are the result of your Git renaming their Git's branch names so they don't conflict with your own branch names.Hence what you want is:
git fetch origin release/2.0.23175_BBDDv10
which calls up their Git, asks them about their release/2.0.23175_BBDDv10
branch, and updates your origin/release/2.0.23175_BBDDv10
name.
This whole thing about where the slashes go, and when, is confusing until you realize two things:
origin
part—isn't a branch name (master
, release/2.0.23175_BBDDv10
) and isn't a remote-tracking name (origin/master
, origin/release/2.0.23175_BBDDv10
). It's a third kind of name, a remote name.master
and release/2.0.23175_BBDDv10
are private to each repository, You can see theirs with git fetch
but your git fetch
renames them to make your remote-tracking names like origin/release/2.0.23175_BBDDv10
.So you always have to remember to ask, when you have a branch name, whose branch name is it: yours, or theirs? Well, you only really have to remember this when you connect both Gits, with git push
, git fetch
, or git pull
(which runs git fetch
):
With git push
, you will have your Git ask their Git to set one of their branch names. You will send them some commit(s) as needed, then your Git will ask them: Please set ______ (branch-name) to ______ (commit-hash ID), if that's OK. (Using git push --force
turns this polite request into a command.)
With git fetch
, you will have their Git look at their branch names, get any new commits from them into your own Git, and then update your remote-tracking (origin/*
) names.
git pull
runs git fetch
, so it does the same as git fetch
. (After git fetch
finishes successfully, git pull
runs a second Git command, usually git merge
. I generally advise avoiding git pull
until you really understand how both git fetch
and the second Git command work, as each step on its own is confusing enough, but this is a personal choice you should make yourself.)
Here's a simple rule for most Git users: never use git fetch --all
.
(It doesn't break anything, but it does not mean what people think it means.)
(The rule for advanced Git users is don't use it yet. Wait, no, that's the rule for optimization. 😀)