Greg
Greg

Reputation: 1803

Github - using someone elses repository

I'm busy with a project which uses some libraries from

git clone http://github.com/adafruit/Adafruit-Raspberry-Pi-Python-Code.git

I've downloaded the above code and put it in my code and now want post my code on github.

I also want to make sure that the latest code from adafruit is always used so is there a way I can put a link in my code to the adafruit so that it always pulls the latest version.

Ive done some reading on git and I think this might be called a fork? When putting my code do I put the adafruit code in my repository, or is there someone I can put a link in to the original?

Upvotes: 2

Views: 7378

Answers (3)

Jordan McCullough
Jordan McCullough

Reputation: 2785

As you have already cloned the repository locally and made modifications, you should take a few steps to create a fork (for traceability to the original) and setup the appropriate remotes to synchronize with.


  1. Go to http://github.com/adafruit/Adafruit-Raspberry-Pi-Python-Code and click the "Fork" button

  2. Copy the Git repository URL for your new Fork

  3. On the terminal, in your project directory, add a remote:

git remote add fork <repo-fork-url>

  1. Ensure your fork is up-to-date in relation to the original project

`git remote update

`git fetch

git checkout master

git pull -rebase origin master

  1. Remove the existing upstream for master; Setup upstream to publish your commits to your Fork

git branch --unset-upstream master

git push -u fork master


From here on, you can edit and commit to your local repository, git push and git pull to sync with your Fork on GitHub, and git pull origin master to retrieve the latest commits from the original repository.

Upvotes: 1

mortusdetus
mortusdetus

Reputation: 97

Yes, by forking your can use pull request to send them your code for review which they merge in their project if they want. To pull the latest changed from their repository see also:

git fetch upstream
git merge upstream/master

It automatically merges if no conflicts but sometimes there are so then you will have to do it manually.

Upvotes: 0

Joachim Sauer
Joachim Sauer

Reputation: 308031

Unless you're already a contributor to that project, you won't be able to push directly to their repository.

In that case the general usecase is to fork the project (i.e. create a copy under your name) and work on that. You can then create pull-request to ask them to pull specific changes from your repository.

This GitHub Article explains the process and also tells you how to keep your fork up-to-date (if you don't do anything special, it's basically just a snapshot).

Upvotes: 1

Related Questions