Search code examples
gitgit-branchgit-extensionsgit-repo

.Git inside git repo and branch are not showing


I'm running into trouble with my git repo. I had a bunch of branch that I realize are missing and I came to this conclusion. My file structure looks like this

REPO-A  
  -/hooks  
  -/info  
  -/objects  
  -/ref  
  -config  
  -description  
  -HEAD  
  -packed-ref  
  -/.git  
    --/hooks  
    --/info  
    --/log  
    --/objects  
    --/ref  
    --COMMITMESSAGE  
    --config  
    --description  
    --FETCH_HEAD  
    --HEAD

When I clone my repo I only see some of my branches that I had and I only have one submodule. If however I delete the /.git file and everything contained under it, I get all my branches back but the ones that I see when the /.git file there are out of date. I was wondering what has happened and how to undo it? I've searched all the reflogs of everyone who’s pushes to the repo but they seem to be all pushes, so I'm a little lost. Any help would be appreciated!


Solution

  • git commands will determine where the git repo is in the following way :

    • it will look for .git/ in .,
    • if not present, it will go up one level, and look for .git/
    • if not present, it will go up one level, ...

    So :

    • deleting the .git/ directory means deleting the repository part, and keeping only the files on disk as they are,
    • if something shows up when you run some git command, this indicates that there is a .git/ directory in some parent directory.

    You can run git rev-parse --show-toplevel to view what git chose as the base directory of your repo.


    If you want to update the branches in that repo, use git fetch and git pull.