I've done something like following:
(1) clone a remote git repository to local host
local# git clone http://www.foo.com foo
(2) add another project on a ssh host(bar) as the second remote repository
local# git remote add bar ssh://bar/home/project
local# git fetch bar
(3) done something stupid on the ssh host(bar):
bar# rm -rf /home/project
Could you please tell me how can I recover project on the ssh host(bar) from my local copy, so other developer on the ssh host can continue their work, and I can run 'git fetch bar' to get their commit, just like I didn't do anything wrong to their ssh host, i.e. undo all I did to host bar. thanks a lot.
UPDATE:
bar# mkdir -p /home/project && cd /home/project && git init --bare
local# git branch remote show bar
local# git push bar bar/master:refs/heads/master
local# git push bar bar/branch1:refs/heads/branch1
local# git push bar bar/branch2:refs/heads/branch2
Git fetch summary In review, git fetch is a primary command used to download contents from a remote repository. git fetch is used in conjunction with git remote , git branch , git checkout , and git reset to update a local repository to the state of a remote.
23. How would you recover a branch that has already pushed changes in the central repository but has been accidentally deleted from every team member's local machines? We can recover this by checking out the latest commit of this branch in the reflog and then checking it out as a new branch.
Instead of one of these:
$ git push bar bar/branchX:refs/heads/branchX
for every ref'd branch in local. Try this
$ git push bar refs/remotes/bar/*:refs/heads/*
The above command should push all the remote refs you had cached locally back to the remote and put them in the right spot.
Note that you also need to push any tags you might have had:
$ git push --tags bar
Also, it helps to know what's going to happen before you actually do the push:
$ git push --dry-run ...(rest of push cmd)
NOTE: I used 'bar' where most people would have 'origin' - replace with the name of your remote.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With