Send a pull request on GitHub for only latest commit

I forked a project on github and am successfully making changes to my local master and pushing to origin on github. I want to send a pull request, but only want to include the last commit. The pull request UI on github.com shows the last 9 commits and I don’t know how to filter that down.

I was trying to understand if I should create a new local branch, check that out and somehow reset or rebase to upstream? Then apply my last commit from my master by id to the new local branch and use that for the pull request?

  • How to give PHP write access to certain directories created by git?
  • Can't clone a github repo on Linux via HTTPS
  • Cloning a git repo succeeds with the command line, but fails with a git GUI client (e.g. SourceTree)
  • Using gitk, can I see the difference between 2 commits?
  • fatal: bad default revision 'HEAD'
  • git - reorder commits safely
  • I’m trying to get the concepts right and figure out the right command lines to do what I need.

  • Get latest from Git branch
  • Managing Twitter Bootstrap repository using deps in Symfony2 and assetic
  • Test for git direct descendant
  • How to replace a git submodule with vendored in code?
  • How do I tell git-svn about a remote branch created after I fetched the repo?
  • Git: How to reset after merging?
  • 6 Solutions collect form web for “Send a pull request on GitHub for only latest commit”

    You need to basically create a new branch & cherry-pick the commits you want to add to it.

    Note: you might need these before the checkout/cherry-pick commands

    git remote add upstream <git repository>

    git remote update

    git checkout -b upstream upstream/master
    
    git cherry-pick <SHA hash of commit>
    
    git push origin upstream
    

    Afterwards, you will see upstream branch on github, switch to it and can submit the pull request with the changes you want.

    Create a new branch starting from the latest commit, which is also in the origin repository:

    git branch new-branch origin/master
    git checkout new-branch
    

    Then use git cherry-pick to get the single commit you want the pull request for. If the branch with this commit is called feature and the commit you want is the latest commit in this branch, this will be

    git cherry-pick feature
    

    Assuming this patch applies without conflict, you got now a branch for which you can do your pull request.

    In a second step, you now need to decide what to do with your feature branch. If you haven’t published your changes on this branch yet, the best procedure is probably rebasing this branch upon new-branch (and removing the last commit, if this is not done automatically by git rebase).

    I ended up in a situation where I had forked a fork and wanted to submit a pull request back to the original project.

    I had:

    • orignal_project
    • forked_project (created from original project at SHA: 9685770)
    • my_fork (created from forked project at SHA: 207e29b)
    • a commit in my fork (SHA: b67627b) that I wanted to submit back to original project

    To do this, I:

    1. created a new branch from the SHA where the original project was forked
    2. pulled all from the original project
    3. cherry picked the commit I wanted to submit as a pull request
    4. pushed it all up to github

    The git commands were something like:

    1. git branch my-feature-request 9685770
    2. git checkout my-feature-request
    3. git pull https://github.com/original_project/original_project.git
    4. git cherry-pick b67627b
    5. git push origin my-feature-request

    Then I picked my-feature-request as the branch for my pull request to the original project.

    This almost worked for me:

    git checkout -b upstream upstream/master
    
    git cherry-pick <SHA hash of commit>
    
    git push origin upstream
    

    The only difference was this:

    git push origin upstream:upstream
    

    I needed to change that last line so that git push would make the upstream branch in my GitHub repo so that I could make PR from it.

    I had already made the commit which I wanted to be able to isolate as a pull request back onto the current branch.

    So I checked out a new branch

    git checkout -b isolated-pull
    

    And here’s where my solution differs from @Kevin Hakanson’s, as I need to reset this branch to the place in the history I want to diff from

    git reset --hard [sha-to-diff-by]
    

    And cherry-pick the commit from which I want to create an isolated pull request

    git cherry-pick [my-isolated-commit-sha]
    

    Finally push it up to the remote

    git push origin isolated-pull
    

    And pull request dat shi.

    The solution to create a new (temporary) branch, cherry-pick and creating the pull request for that branch did not satisfy me. I did not want to change my repository to make a set of commits available, so I came up with the following alternative:

    First create patch files for all commits of interest:

    git format-patch -1 <sha>
    

    If the commit of interest happens to be the last one you can use HEAD instead <sha>.

    Now, you can send the patches to the maintainer of the source repository, who can apply them:

    git branch new-branch <master or some older commit where the fork diverged>
    git checkout new-branch
    
    git am < <the patch>
    ...
    
    git checkout master
    git merge new-branch
    

    Finally this should look the same as if a temporary branch was merged by a pull request, but without having that additional branch in the fork-repository.

    Git Baby is a git and github fan, let's start git clone.