Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Working with a forked git repository, except I cloned the public repo URL, not the private URL

Tags:

git

github

New to git, so this is hopefully a simple question with a simple answer.

I forked a repository on GitHub. I then cloned it on my local machine by using the public repo URL: [email protected]:samuelclay/django-mingus.git, as opposed to the private repo URL: git://github.com/samuelclay/django-mingus.git.

I made some changes to the code, committed those changes, and in order to push my changes up to my forked repo, I issued: git remote add upstream git://github.com/samuelclay/django-mingus.git, and then git push upstream, but while that doesn't give me an error (it says Everything up-to-date), it is certainly not pushing my changes up to GitHub.

Is there a way to change to the private repo URL? Is that even necessary?

like image 343
Samuel Clay Avatar asked Jan 16 '10 03:01

Samuel Clay


People also ask

Can you clone a forked repo?

You can make a local copy of your forked repository on your computer with the git clone command. Data Tip: You can also copy the URL directly from your web browser, or in some cases, you might already know the URL.

How do I change a forked repository to private?

Just go to https://github.com/new/import . In the section "Your old repository's clone URL" paste the repo URL you want and in "Privacy" select Private .

Are forked repositories private?

Forks of public repositories are public, and forks of private ones are private. Removing access to a private repository deletes that person's fork. Deleting a private repository deletes all forks of it, which are also private. If you wish to keep a copy, you have to clone and publish it yourself.

Is cloning a repo the same as forking?

The quick answer Forking creates your own copy of a repository in a remote location (for example, GitHub). Your own copy means that you will be able to contribute changes to your copy of the repository without affecting the original repository. Cloning makes a local copy of a repository, not your own copy.


2 Answers

I was able to easily do this by editing the .git/config file.

$git clone git://github.com/user/test.git # Clone from read only
# Make changes
$ git push
fatal: remote error: 
  You can't push to git://github.com/user/test.git
  Use [email protected]:user/test.git

So I edited .git/config for that project and changed the origin's url:

[remote "origin"]
    fetch = +refs/heads/*:refs/remotes/origin/*
    # Remove this line:
    #url = git://github.com/user/test.git
    # Add this line:
    url = [email protected]:user/test.git
[branch "master"]
    remote = origin
    merge = refs/heads/master
$ git push
Counting objects: 5, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 298 bytes, done.
Total 3 (delta 2), reused 0 (delta 0)
To [email protected]:user/test.git
   58986b8..c8bd8c2  master -> master

Success!

like image 89
csexton Avatar answered Oct 06 '22 02:10

csexton


You've gotten the public and private URLs backwards. The git:// URL is the public one; the git@github URL is the private one.

If you want to change a repo URL, just open up your .git/config file in a text editor, find the offending URL, and change it to the other one. Check the git config documentation for more information on the format of the config file.

like image 26
Brian Campbell Avatar answered Oct 06 '22 00:10

Brian Campbell