Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
263 views
in Technique[技术] by (71.8m points)

github - Existing git (private remote) repo already exists. No way of getting in contact with previous developer

Imagine. You just got a new side-gig. You are given root access to the application. You ssh into the server. You perform a:

 git status

and you see:

 Your branch is up to date with 'origin/master'.

Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
 modified:   .htaccess
 modified:   office/.htaccess
 modified:   office/error_log
 modified:   office/wp-admin/error_log
 modified:   template/default/javascript.js
 modified:   www2/.htaccess

Untracked files:
 (use "git add <file>..." to include in what will be committed)
   public_html/

no changes added to commit (use "git add" and/or "git commit -a")

"okay" you think to yourself. You then run a:

 git config --list

and you see

 core.repositoryformatversion=0
 core.filemode=true
 core.bare=false
 core.logallrefupdates=true
 [email protected]:somecoolguy/somecoolproject.git
 remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
 branch.master.remote=origin
 branch.master.merge=refs/heads/master

You then visit github and check on somecoolguy's project and notice that it's private.

You'd like to transfer the repo to another git remote location, maintain the history, and not lose any of the uncommitted changes such that you can begin working on this project and have full ownership of your own repo moving forward...

What do you do?

question from:https://stackoverflow.com/questions/66051665/existing-git-private-remote-repo-already-exists-no-way-of-getting-in-contact

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Even though somecoolguy's account in Github is private, you have an entire copy of the git repository in the server (Your branch is up to date with 'origin/master'). You should be able to create a new repository in Github under your account and add it as another remote where you can push the git history.

git remote add anotherorigin [email protected]:myaccount/somecoolproject.git

Notice that this remote is pointing to your account instead of somecoolguy's.

If you don't want to play around with SSH keys (as the keys in the server probably belong to somecoolguy), you can link the new origin using https which will require your Github credentials when pushing:

git remote add anotherorigin https://github.com/myaccount/somecoolproject.git

Once you do that, it should be enough to push your repository to the new remote server. If you don't want to lose the changes that have not been committed yet, you can always commit the uncommitted files before pushing:

git add .
git commit -m "New commit"
git push anotherorigin master

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...