views:

57

answers:

3

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 status' command is targeting a new repo to compare itself to? Equally, am I missing something else very important :D ?

Thank you everyone.

A: 

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
mipadi
Ok I did all that. But how do I push the new code I've written on my local on to my new repository if my current git status is clean?
Trip
Your `git status` is just the status of your *working copy* files. You push the repo using `git push`. If there are differences between your local repo and the remote repo, the changes will get pushed up.
mipadi
+3  A: 

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.

VonC
Wierd. It returns "error: unknown option `set-upstream'" I wrote what you had their exactly.
Trip
@Trip: what version of git are you using? `set-upstream` has only been introduced since git1.7.
VonC
A: 

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 [email protected]: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.

Trip
@Trip: right, I had forgot about the `git fetch` step. I have amended my answer to reflect that step.
VonC