I have a Git working directory that I would like to use to create a new master, keeping the existing commit history (etc.) intact. The reason for this is that my original remote master has become corrupt, and the working directory has had updates made to it since.
I've tried a Git clone of the working directory, but I am unable to push to the cloned directory. A get a similar problem if I do a straight copy and paste of the working directory to my Git server.
How do I convert my local working directory to a new master on a remote server?
I'm a newbie when it comes to Git, so a simple explanation without too much jargon would be really helpful.
If I understand your question correctly you are looking for this
git remote set-url origin https://blabla.com/newrepo.git
git push origin master
This will retain all your current history but allow you to push to a different remote repository.
I guess you are getting the error that you cannot push to the remote repo because branch whatever is currently checked out (like here: Git push receiving "error: refusing to update checked out branch" ).
To create a bare repo (this is a repo with full history but without checked out working copy), do a
git clone --bare yourrepo barerepo.git
Then, take the barerepo.git
directory and move it to the machine that should host it.
One done, add the repo as a remote to yourrepo
git remote add origin /path/to/barerepo.git
Then, you should be able to
git fetch origin
git push origin
However, the question sounds like you want to restore a crashed remote repository from a local one. Had the same issue one week ago: How do I restore a remote crashed Git repo?
Maybe you can force the push to the remote master branch from your local one, using the --force
parameter, but I wouldn't recommend it if you don't know what you are doing.
-f --force Usually, the command refuses to update a remote ref that is not an ancestor of the local ref used to overwrite it. This flag disables the check. This can cause the remote repository to lose commits; use it with care.
https://www.kernel.org/pub/software/scm/git/docs/git-push.html
So something like this :
git push --force origin master:master
The first master
represents the local branch you want to push, and the other master
represents the remote branch you are pushing to.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.