From the main repository on github, I created a fork on github and I keep the master branch of my fork up to date with the main repository by doing:

git checkout master
git pull upstream master
git push

where upstream is set to the URL of the main repository.

I do this on the command line. It might be nice to be able to do that from within magit (emacs) but that isn't my question right now.

I then make a pull request by doing something like:

git checkout -b new-branch
... create changes including commits within emacs ...
git push --set-upstream origin new-branch

then go to github and make the pull request via its GUI. I'm fine with the GUI github part but if that can be simplified, I'm interested in that as well.

The last two git commands is what I'd like help with the most. I've read the documentation but find it hard to follow.

I have magit 2.12.1 and git 2.17.2 but I'm happy to update either if that will help. Also, I realize that the above sequence may not be optimal so I'm open to changing the sequence.


The convention is to name the upstream repository origin. I think it is a good idea to stick to that convention, but I guess naming the upstream repository upstream also makes a lot of sense. However it is a bad idea to name a repository that is not the upstream origin. Doing that is really confusing.

When you clone a repository using git clone <upstream-url>, then that automatically creates a local branch namedmasterwhich hasorigin/masterset as its upstream. If you insist on naming that remoteupstream, then you can do the same usinggit clone --origin upstream `.

To get your local version of another remote branch, e.g. origin/new-feature use b c origin/new-feature RET RET. Before you do that you should git config --global branch.autoSetupMerge always once. After doing that the upstream branch is automatically set when creating a new branch from an existing remote branch. Without that this is only done if the source is a local branch. I.e. the default value of that variable is a really bad one.

Now to your question...

Do not change the upstream when pushing. A branch can have two other branches associated with it the upstream (the branch on top of which you add new commits and into which you would like your changes to be eventually merged) and the push target (the branch where you push your changes so that you can ask the maintainer to merge it (into the upstream)).

The manual has information about the two remotes.

To push to the push remote, i.e. your for badly named fork origin type p p origin RET. You only have to type the origin once per branch, afterwards you can just use p p. This assumes that you have set `

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.