I cloned a git repo to my local machine, played around with it a bit and found it cool.
Now I would like to keep the result as I modified it in my own github space. How can I proceed?
I suppose the regular way would have been to fork the repo on the first place to my space, clone it, modify and then push it to GitHub, but now I cloned the original's author repo, how can I commit that as a new thing in my personnal?
So you've cloned somebody's repo from github, but now you want to fork it and contribute back. Never fear! Technically, when you fork "origin" should be your fork and "upstream" should be the project you forked; however, if you're willing to break this convention then it's easy.
The quick answerForking 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.
First rename the old remote as upstream, in case you want to be able to keep in sync with the original repository.
git remote rename origin upstream
Then add your forked repository as origin:
git remote add origin https://github.com/<your-username>/<your-project>
Or if you're using ssh:
git remote add origin [email protected]:<your-username>/<your-project>.git
To push to your repository:
git push -u origin master
To pull from the base repository:
git pull upstream
I recommend you do all of your work in a separate branch, not the master branch. It will be easier to rebase to the upstream/master
branch in case you want to make a pull request.
You don't really have to rename the origin
to upstream
- the remote names can be arbitrary, however I recommended you to do so to keep up with the naming convention used by GitHub.
On the github webpage create a fork in the usual way. Then go to your repository and add a remote which points to your fork: git remote add myfork [email protected]:you/your-fork.git
. This adds a remote called "myfork" which you can push to. You could also change the url of the "origin" fork; this will get you exactly the same state as if you had cloned from your fork to begin with: git remote set-url origin [email protected]:you/your-fork.git
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With