2

This is probably a basic question about .git, but I am not used to use the rebase functionality. I understand it is one way to integrate latest changes from Master to a local branch.

Does it prevent the creation of pull requests or is there any pitfall I should be aware of? I believe I can push my local branch changes to the main repository after a rebase and then create a pull request for integration in Master there, right?

Jérôme Verstrynge
  • 57,710
  • 92
  • 283
  • 453

1 Answers1

4

A "pull request" isn't a concept in the Git object model.

A pull request is an offer of some new code to a project. Essentially, "please merge the changes I made into your project's stream".

"Creation of a pull request" isn't a Git operation, though Git has a request-pull command which summarizes some changes into a textual message.

The git pull command fetches objects from a remote repository (like git fetch) and then performs a git rebase or git merge, depending on which action is configured as a the default.

You might be confusing Git, the version control tool with the facilities of some project hosting site based around Git (whose "pull requests" might not be based on using the output of git request-pull at all.).

git pull and "pull request" are completely different things. In fact, you wouldn't want to fullfill someone's request to add code to your project by doing a blind git pull from their repository.

As a general rule of thumb, if you want to make it as easy as possible for someone to incorporate some patches you have made to their project, it behooves you to rebase those changes to their latest codebase, so that they cleanly apply on top without any merging. Project maintainers generally don't want to hear, "I made some changes based on a copy of your project I retrieved back in 2011; can you merge them for me?"

However, if you tell someone you have some changes at a specific GIT repo you'd like them to use, identified by SHA commit hashes, and then you rebase those changes, that person effectively has a stale request which points to the old, un-rebased version of your changes.

Git has a command request-pull which is basically a query that creates a pull request, which is just a textual message identifying and summarizing some changes. The command also performs a sanity check that the advertized range of changes is actually available at the given git URL, which catches you if the URL is incorrect, or you didn't push the changes there yet (you're accidentally advertizing a pull request out of some unpublished changes in a local repo).

Kaz
  • 55,781
  • 9
  • 100
  • 149
  • Ok. So, can I safely assume that a rebase in git does not prevent the creation of a pull request in github? – Jérôme Verstrynge Dec 03 '15 at 19:15
  • No Idea; I don't use github. You didn't mention github in the question, and there only a git tag. I can only generally assume that you want to be rebased to the latest upstream code to have the best possible chance to have your changes accepted. – Kaz Dec 03 '15 at 19:18
  • 1
    Just to complement this good answer: no, a rebase in git does not prevent the creation of a pull request in github. After you rebase, you will have a resulting commit with which you can create a PR. Please see this question and answers: http://stackoverflow.com/questions/14680711/how-to-do-a-github-pull-request – iled Dec 03 '15 at 19:21
  • You're saying that when we `pull` from a Git Hub repo and somehow end up with a `pull request` in the commit history, that's a GitHub thing and not a Git thing? – Dan Rosenstark Dec 03 '15 at 19:22
  • https://git-scm.com/docs/git-request-pull So git a pull request is a git concept? – Dan Rosenstark Dec 03 '15 at 19:24
  • 1
    I've never seen `pull request` in a git history. `git pull` does a `git fetch`, followed by `git rebase` or `git merge`, depending on which one is the default. `git rebase` never generates new commit messages. `git merge` can create merge commits. – Kaz Dec 03 '15 at 19:24
  • 1
    @Yar When you `pull` from a repo you are fetching objects from that repo. You do not end up with a `pull request`in the commit history. Basically, a `pull request`, i.e., in GH, is the same as asking (request) someone to `pull` from your repo. – iled Dec 03 '15 at 19:26
  • @Kaz, so a pull request is indeed a git thing. You have updated your answer. I'll approve it considering Iled's first comment. – Jérôme Verstrynge Dec 03 '15 at 20:23