0

In my school we have to create exercises based on API Rest. The repo is hosted on Github. We have each a subfolder and a branch to work on. However, when I wanted to try others exercises, the git checkout [branch] didn't changed the branch and no error message was displayed. I had to move into the subfolder to checkout the branch and then add it to my local repo.

Can someone explain why is this happening ? It's not the first git project I work on but I've never seen this behavior.

And is there a way to fetch all branch at the same time ? I've looked here but except telling me that the repo is up to date it does nothing...

Update

I can checkout any branch from any subfolder, but not form the root folder of the repo. But if I checkout from the root for a undefined branch name, it returns error: pathspec 'asdkf' did not match any file(s) known to git.. With a correct name it says and does nothing.

OnStandBy
  • 79
  • 1
  • 1
  • 8
  • Do you have separate repos for each of those subfolders? This would explain your observations. To see what repo you are in, type `git status` from the Git bash, and it will tell you. – Tim Biegeleisen Apr 17 '18 at 06:41
  • Have you created git repositories in the subfolders as well? – Lasse V. Karlsen Apr 17 '18 at 06:41
  • No, just made branch from master – OnStandBy Apr 17 '18 at 06:50
  • It depends on where the `.Git` folder resides. `Git` commands work where there is `.Git` is present – Sravan Apr 17 '18 at 07:08
  • .git is only in the repo's root folder – OnStandBy Apr 17 '18 at 07:09
  • You might be missing the point when you clone only a single branch (typically "master") is created *to track* the same-named branch in the source repo. All the other branches end up becoming the so-called "remote branches" in the resulting local repo. So, if you did something like `git clone https://github.com/foo/bar` and it contained branches "quux" and "frob", those became remote branches named "origin/quux" and "origin/frob" in the resulting repo. – kostix Apr 17 '18 at 10:22
  • To check such a branch out, you do `git checkout -b quux origin/quux` which means "check out a *new* local branch «quux» which points at the same commit a remote branch «origin/quux» points at and make the former track the latter". – kostix Apr 17 '18 at 10:23
  • @Sravan, that directory is named ".git" — strictly all-lowercase. You might be on Windows, where that does not matter (unless bites you in the rear in weird cases), but on on case-sensitive filesystems, it does. – kostix Apr 17 '18 at 10:24
  • @OnStandBy, read [this](https://git-scm.com/book/en/v2/Git-Branching-Remote-Branches) for more background on the asymmetry between your local repository and the repositories it communicates with. – kostix Apr 17 '18 at 10:25
  • Reading again your explainations but it's still not fit the issue. Maybe it has change since but here I just did `$ git clone [urlOfRepo]` then `$ cd [clonedRepo] && git checkout develop` and nothing changed, no error message was sent. Still, today I did it at least 6 times, I could checkout without any options and it worked as it should. – OnStandBy Nov 28 '18 at 13:22

1 Answers1

0

After one year I come back here to close this question, if you're experiencing something similar, try to checkout the branch in a sub-folder of your repo. I'm more experienced now and I can tell that I did nothing wrong to cause this issue. Oh and in my classroom I was obliviously the only one to have the issue.

Here's what I did :

  1. $ git clone [repoUrl]
  2. $ cd [clonedRepo]
  3. $ git checkout [anyBranch] > Nothing happened
  4. $ git checkout [non-existing branch] > error: pathspec 'asdkf' did not match any file(s) known to git.
  5. $ cd [anySubFolder]
  6. $ git checkout [anyBranch] > Branch checked out without any problems

Still a better issue than git completely ignoring .gitignore

OnStandBy
  • 79
  • 1
  • 1
  • 8