Suppose that I create an empty GIT repo with the following command:
# git init
Then I start adding remote repositories:
# git remote add remote1 ........
# git remote add remote2 ........
# git remote add remote3 ........
and fetching:
# git fetch --all
Finally, I merge into my local repo all the remote branches that I need:
# git merge remote1/branchX
# git merge remote2/branchY
# git merge remote3/branchZ
Now, suppose I have to reset my local repo at before all the merges; the natural solution seems to be to just create a new empty repository. But the problem is: the fetch of my remote repositories takes a very long time (hours), so I would like to avoid to re-fecth all again.
I cannot do a “git reset” because I do not have a commit preceeding all the merges.
A decent way to cheat this is to do a
git init && git commit --allow-empty -m 'Initial commit.'when you set up the repository, which alleviates the symptom of a non-existentHEADat least.But since you’ve fetched all of the remotes already, you do not need to blow away the repository in order to create a new empty/unrelated branch if that’s more what you’re looking for:
Then when you commit/merge whatever on
HEAD, git will fill in the new branch for you. Once you have another existing branch you can hard reset master or do whatever other tricks you’d like to juggle them around.