开发者

How to switch repositories from one to the next

开发者 https://www.devze.com 2023-01-05 02:33 出处:网络
I was using a github repository from a previous developer. I am the only coder on this project, so I forked the project over to my own github repository.

I was using a github repository from a previous developer.

I am the only coder on this project, so I forked the project over to my own github repository.

Now I would like to commit soley to my repo.

Unfortunately, I realized that I never changed my .git/config , so I was still committing to the old repo. I just changed it to the appropriate url, and when I type :

$> git status

It returns :

=> Working directory clean.

But I know its not because I have several commits I've made. So my local box has different code then what it is pointed to on my repository.

My question is this. Obviously I'm halfway through the process of doing this. Do I need to re-fork to update, and then I'm good. Or is there a special command I need to run to let my local box know its 'git s开发者_如何学JAVAtatus' command is targeting a new repo to compare itself to? Equally, am I missing something else very important :D ?

Thank you everyone.


You can use git remote to manage your remote

  • rename origin
    git remote rename origin old_origin
  • add a new origin
    git remote add origin git://github.com/my/forked/repo.git
    git fetch origin # will create all the remote branches references 
                     # in your local repo

You can also easily setup a new upstream for your current master branch (git 1.7 and more):

git branch --set-upstream master origin/master

The "nothing to commit (working directory clean)" message of git status won't prevent you to push.
After changing the origin, you should see:

$ git status
# On branch master
# Your branch is ahead of 'origin/master' by xxx commits.
#
nothing to commit (working directory clean)

That means you have some commits to push to your new origin.


Note: "git remote"(man) rename failed to rename a remote without fetch refspec, which has been corrected with Git 2.39 (Q4 2022).

See commit 5a97b38 (22 Sep 2022) by Jeff King (peff).
(Merged by Junio C Hamano -- gitster -- in commit 20a5dd6, 10 Oct 2022)

remote: handle rename of remote without fetch refspec

Reported-by: John A. Leuenhagen
Signed-off-by: Jeff King

We return an error when trying to rename a remote that has no fetch refspec:

$ git config --unset-all remote.origin.fetch
$ git remote rename origin foo
fatal: could not unset 'remote.foo.fetch'

To make things even more confusing, we actually do complete the config modification, via git_config_rename_section().
After that we try to rewrite the fetch refspec (to say refs/remotes/foo instead of origin).
But our call to git_config_set_multivar() to remove the existing entries fails, since there aren't any, and it calls die().

We could fix this by using the "gently" form of the config call, and checking the error code.
But there is an even simpler fix: if we know that there are no refspecs to rewrite, then we can skip that part entirely.


git status only shows you the status of your working directory, not the entire repository. It seems like you only need to change the remotes that git push and git pull use by default. Open up .git/config and find your branch.<branch> entries and change them, as well as your remote.<remote> entries. For example, your master entry may look like this:

[branch "master"]
    remote = origin
    merge = refs/heads/master

Just change remote to reference your (forked) remote.

Also, your remote entry may look like the following:

[remote "myremote"]
    url = git://github.com/me/repo.git
    fetch = +refs/heads/*:refs/remotes/origin/*

You can add a push entry so that your master branch is pushed by default:

[remote "myremote"]
    url = git://github.com/me/repo.git
    fetch = +refs/heads/*:refs/remotes/origin/*
    push = master


In whole, but I should include it in this answer. Is that before hand I manually altered my .git/config to include my new repository url. That's why I didn't have to rename or add any origin as Von suggested.

Then I just guessed this and performed

 $> git fetch origin

Which returned

From git@github.com:gotoAndBliss/hq_channel
 17326ca..043d395  master     -> origin/master
 * [new branch]      panda_streaming -> origin/panda_streaming
 + 6ec9bf8...becbcc6 testing    -> origin/testing  (forced update)

Then on git status I got

# On branch testing
# Your branch is ahead of 'origin/testing' by 9 commits.

I git pushed origin testing, and I think I'm on target now.

0

精彩评论

暂无评论...
验证码 换一张
取 消