GitHub: Cloning your own project

Today I released the first version of MySQLBuddy. It is basically a fork of SybaseBuddy where I’ve removed a few things (for Sybase) and made a few changes for MySQL. So I wanted to fork SybaseBuddy in GitHub to a new project. Unfortunately it looks like GitHub doesn’t support this. It seems to assume that the owner of a project will not fork his own project.

Here is what I did to fork the project:

I first created a new GitHub repository: MySQLBuddy.
Then I created a clone of SybaseBuddy on my machine:

$ git clone https://github.com/benohead/SybaseBuddy.git MySQLBuddy
Cloning into 'MySQLBuddy'...
remote: Counting objects: 105, done.
remote: Compressing objects: 100% (78/78), done.
remote: Total 105 (delta 33), reused 74 (delta 7)
Receiving objects: 100% (105/105), 6.48 MiB | 1.38 MiB/s, done.
Resolving deltas: 100% (33/33), done.

Now I had a clone but needed to teach it that it’s not linked to the SybaseBuddy GitHub repository anymore but to the MySQLBuddy repository. For this you need to update the .git/config in your clone:

Under Linux:

$ sed -i 's/SybaseBuddy/MySQLBuddy/g' .git/config

Under Mac OS X:

$ sed -i .tmp 's/SybaseBuddy/MySQLBuddy/g' .git/config

Or simply edit the file and update the URL to the repository.

Now you need to push this clone to the new repository:

$ git push -u origin master

You might get the following error message:

$ git push -u origin master
To https://github.com/benohead/MySQLBuddy.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/benohead/MySQLBuddy.git'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes (e.g. 'git pull') before pushing again.  See the
'Note about fast-forwards' section of 'git push --help' for details.

What you need to do is first pull from the repository before pushing:

$ git pull

You might also get there the following error message:

$ git pull
warning: no common commits
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
From https://github.com/benohead/MySQLBuddy
 + c1c2949...820a952 master     -> origin/master  (forced update)
Auto-merging README.md
CONFLICT (add/add): Merge conflict in README.md
Automatic merge failed; fix conflicts and then commit the result.

So you’ll need to handle the merge manually. Just update the file (here README.md) and pull again.

For some reason, I did the following before modifying the file:

$ git pull
U	README.md
Pull is not possible because you have unmerged files.
Please, fix them up in the work tree, and then use 'git add/rm <file>'
as appropriate to mark resolution, or use 'git commit -a'.
$ git commit -a
[master 00dd552] Merge branch 'master' of https://github.com/benohead/MySQLBuddy

But you don’t need to do it like this and can directly modify the file and pull.

After that you’ll be able to push:

$ git push -u origin master
To https://github.com/benohead/MySQLBuddy.git
   820a952..00dd552  master -> master
Branch master set up to track remote branch master from origin.

And you’re done !

Leave a Reply

Your email address will not be published. Required fields are marked *