How to submit a pull request from a cloned repo? - github

How to submit a pull request from an existing locally-cloned repo?
Often, I want to look at some libraries source code from github, so I clone it. Later, I discover some issue with the code and raise it on a mailing list, often in passing. The library author says "nice find, can you send a pull request?".
And the answer is "not that easily". I haven't forked the repo yet, Ive cloned it. And there doesn't seem a way I can find to submit a pull request from a cloned repo?
If this limit is true, it feels like the sensible reaction is to fork anything and everything you ever look at, just so that if you ever might want to contribute, you can. And that fills up your github account with many inactive forks.
Doesn't seem a lot of talk about this issue - am I the only person whom this problem affects?

Fork the repo on GitHub, then add your fork repo as a remote to your local cloned copy:
git remote add myfork https://github.com/<myGitHubAccountName>/<repoName>.git
Then you can push to your fork:
git push myfork master
If you're doing more than just this one pull request, you can remove the origin remote and name your fork as origin:
git remote rm origin
git remote add origin https://github.com/<myGitHubAccountName>/<repoName>.git
This is typically what I do. Sometimes I add the original origin as upstream so I still have a reference to it.

If you're ok with installing another binary in your path, github has released a nice little tool called hub.
If you've cloned someone else's repo:
$ hub fork # This creates a fork and adds your repo as a remote
$ git push YOUR_USER feature # push the changes to your new remote
$ hub pull-request # will open your browser

I always clone instead of fork as well and the following steps work for me:
Create a new branch on your cloned repo and make the new change.
Push the change to your branch as the following:
git push origin insert_your_working_branch_name
Now you should be able to find your working branch in pull request from github master.

Related

Pull fork and submit pull request

I am working with GitHub and want to submit a pull request. When I fork the repository I don't see my changes I'm guessing because it never asked me where to link the repository to. How do I link the forked repo to a location on my personal computer for the pull request? This is for an interview and with the code done I don't know where (or how) to put it.
I'm the first to oppose noise but I don't know what other exchange site to post on. I'll close it if I'm pointed somewhere else and it doesn't get closed first.
If you have cloned the original repo locally, you can:
make sure you have a fork on GitHub (you seem to have one, where you say you don't see your changes, which is expected since you haven't push them yet)
declare that fork as your new origin
That is
cd /path/to/my/local/repo
git remote rename origin upstream
git remote add origin https://github.com/<myGitHubAccount>/<reponame.git>
Don't forget to add your changes, commit and push:
git checkout -b aNewBranch
git add .
git commit -m "Fix done in a new branch for PR (Pull Request)"
git push -u origin aNewBranch
From there, you can go to https://github.com/<myGitHubAccount>/<reponame.git>, switch to aNewBranch, and click "Make a Pull Request"

Github - merging fork into master (locally)

So i have the following problem:
Back when i started programming, i FORKED a repository (using github for windows) for a browser-game. For some time now, i made stuff, did git commit and issued a pull request using the webpage.
The original author did authorize my pull request and my changes went live.
Recently, i have become an "official" author on the original repository.
So i dont want to work on my "fork" any longer but instead dev on the original.
Using github for windows, i decided to "clone" the original repo.
My github now shows my forked (AncientSion/FieryVoid) repository and the original (Aatu/FieryVoid).
Now what i would like to do is somehow "merge" my forked repo into my local clone of the original repo and from there commit to the master repo directly, that way deploying my local, not yet commited changes from my fork to the live version while at the same time getting rid of fork repository.
However, i have no idea if that works and if it does, how.
Can someone please advise ?
I don't think that the Github for Windows interface supports this, but this can definitely be done via the git bash console. This is untested, but the steps ought to be correct, since I've done something similar (identical, in fact) before. This assumes that your clone, AncientSion/FieryVoid, is up-to-date with Aatu/FieryVoid, which can be done with a pull followed by a merge, or, to avoid merge commits, with a git pull --rebase. So now you have AncientSion/FieryVoid and Aatu/FieryVoid, both present locally, with AncientSion/FieryVoid ahead of Aatu/FieryVoid by a few commits. What you need to do is pull in those commits into Aatu/FieryVoid by running the following:
cd path/to/local/clone/of/Aatu/FieryVoid
git remote add local_pull path/to/local/clone/of/AncientSion/FieryVoid
git pull local_pull master
git push origin master
Couple of assumptions:
You were working on the master branch of AncientSion/FieryVoid. If not, replace master in line 3 with your branch name.
origin is a remote that tracks the online repo Aatu/FieryVoid

Is there a quick way to shift to a fork in github?

The following happens to me from time to time:
clone something from github
discover something I want to fix.
want to offer it back.
Go make a fork
clone my fork
manually merge my changes to the fork
open a pull request
Somehow, it seems to me that there should be a simpler way to get from 'I've got local changes in a local branch' to 'I've got changes in a fork I can submit a pull for.'
Is there?
Github has the hub gem for maniplating their API.
Secondarily ( and I think what you're looking for) you can add a second remote to your original repo like
git remote add myfork git://github.com/defunkt/hub.git # for the case of hub
and then
git push -u myfork branchname
to push branchname up to your fork from the original repo. The -u flag sets that branches upstream to be your fork.

Are Github pages created automatically in the fork of a repo which has a gh-pages branch?

Are github pages within my account created automatically when I fork a repo which already includes gh-pages branch?
There needs to be at least one push to trigger a page build so by doing a git push origin master, I got the page to rebuild.
An elegant approach:
git push -f origin gh-pages^:gh-pages
git push origin gh-pages:gh-pages
git push origin master might not be good because if there might already be something on master. The above should always work, as it just wobbles the remote branch back and forward.
Taken from: Pushing without committing , whose solutions are also solutions to this question.
Forking a repository within Github is not sufficient by itself to trigger the creation of the Github Pages.
Either of these two things will work:
Edit and save any page using the Github interface. For example, modify the README.md file, even just adding a space.
Make any kind of git push to the gh-pages branch. As others have suggested, a trivial non-change you can make is:
git push -f origin origin/gh-pages^:gh-pages
git push origin origin/gh-pages:gh-pages
This force-pushes the penultimate commit to be the gh-pages HEAD, then fixes it.
After you fork a github page repo, you can change any file on github page and commit it, your web site will appear without using git.
Renaming the forked repository would work too.
No, after you fork a repo, you have to publish it again. To do this, run the following commands on a local clone:
git push -f origin origin/gh-pages^:gh-pages
git push origin origin/gh-pages:gh-pages
This triggers the publisher hook twice, but you don't have to commit anything.
You would have to publish it afresh from your forked repo directory
Run:
git push origin main

How to push changes from a forked project to the original project?

I’m supposed to work on my client's project on GitHub, where the changes would be on his repository. I tried to follow the fork example, but could only get the changes to go to my account repository?
In the example on GitHub, to fork a repo, they create a remote called upstream to point to the original project. I can get the changes from it by
get fetch upstream
git merge upstream/master
I was able to upload the changes into my repo by
git push –u origin
which copied my changes to my account.
I tried
git push –u upstream
To push my changes on the original account. I got the following error
You can’t push to git://github.com.octocat/SpoonKnife.git
use git#github.comoctocat/Spoon0-Knife.git
Basically, in order to collaborate with your client, you've got two main options:
Send your client a pull request (more info on this in this GitHub help item). This allows your client to review, discuss and/or request some changes to your proposal before merging it.
Request from your client to be added as a committer to their project. This would allow you to directly push your commits to their repository, without the need for a fork/cloned repository on your side.
As a side note, Spoon-Knife.git is one of GitHub's read-only repository (used for demonstration purpose) and you will not be able to commit to that (unless your client is GitHub). Thus, your client's upstream git remote should point to a different repository
Here are the steps (to be followed after you forked and cloned the repository to your local disk):
Remove the upstream reference: git remote rm upstream
Add in your client's info - git remote add upstream git#xxxxxx
Push your changes - git push -u upstream master . git push -u will set the HEAD of the remote repository.
Same if you want to pull - git pull upstream master
If you prefer the name origin replace upstream with origin, but still follow step 1 to remove the reference to Spoon-Knife.git. Then in step 2 - git remote add origin git#xxxx.
git://github.com.octocat/SpoonKnife.git is a read-only URL. As GitHub suggests, the corresponding write-able URL is git#github.comoctocat/Spoon0-Knife.git.
If you want to be able to push on the upstream repository, you will have to ask (to the upstream team, i.e., your customer) to be added as a committer.