2

With some help I managed to recover a local git project from a fatal: not a git repository (or any of the parent directories): .git issue... Why does git not recognise my local repository?

But now my local git is ahead on a new local branch (that doesn't exist on the GitHub remote) and is disconnected from the existing remote origin.

  • git remote -v returns nothing

How do I reconnect and push the local git to the existing GitHub remote without losing the new local branch with it's commits?

Dan
  • 229
  • 2
  • 6
  • `is disconnected from the existing remote origin` can you clarify what this means please, e.g. by adding the command and output when you try `git checkout my-branch; git push` to the question? – AD7six Mar 27 '21 at 15:31
  • Added `git remote -v` thanks @AD7six , I'll try to get into the habit of that. – Dan Mar 27 '21 at 20:51

1 Answers1

3

Add the remote:

git remote add origin http://github.com/user/repo.git

Then push the changes.

evolutionxbox
  • 3,932
  • 6
  • 34
  • 51
jessehouwing
  • 106,458
  • 22
  • 256
  • 341
  • Ok that's simpler than I thought thank you! One question though, does this automatically track all the existing branches or do I need to use `git push -u origin branch` for each branch? – Dan Mar 27 '21 at 20:51
  • 1
    Figured it out, all the branches need to be reset to track the relevant remote branch by using `git push -u origin branch` for each branch – Dan Mar 27 '21 at 21:00
  • 1
    @Dan: actually you need only a `git branch --set-upstream-to` for each branch. The `git push` option `-u` means: *after a successful push, run `git branch --set-upstream-to` as well*. Note that each branch has either no upstream, or one upstream, so if some branches already have an upstream set (though none will in this particular case) this could *change* the upstream, if you pick a different one this time. For more about upstreams, see my answer to [this question](https://stackoverflow.com/q/37770467/1256452). – torek Mar 28 '21 at 01:11