-
Couldn't load subscription status.
- Fork 4.9k
Beginner's Guide to Contributing a Pull Request to Spacemacs
This guide is mostly a reproduction of @travisbhartwell's great introduction post on his blog. The primary changes pertain to Git branching strategy (and nomenclature) and the addition of git CLI commands. They're not meant to be used side-by-side and can be confusing if you do so. Please use either one or the other as a guide. (P.S. If reading such a long post is not your forte, he has also created a handy video tutorial covering the same topic.)
Create the fork by visiting the Spacemacs project page on Github. If you happen to belong to organizations on Github, you will be prompted to select where to fork the repository; select your user in this case.
This will create a new repository for your user that is a mirror of the current state of the upstream repository.
Note/Copy the repository clone URL that is shown on the right-hand side of the page, part way down. This is needed when you clone your repository to your local filesystem in the next step.
Next, you need to clone your fork of Spacemacs to a local directory (preferably ~/.emacs.d). This can be done by typing git clone [email protected]:<YOUR USERNAME>/spacemacs.git ~/.emacs.d from the command line. Please ensure to backup your existing dot-emacs directory by typing mv ~/.emacs.d ~/.emacs.d.bk; just in case you decide to change your mind later.
You now need to add Spacemacs upstream as an upstream to your clone.
-
Go to
magit-statusfor the Spacemacs repository by doingSPC u SPC g s(Hit the spacebar, then u, then the spacebar again, then g, then s). Then enter the path of the Spacemacs repository,~/.emacs.d, and hitRETURN.If you're using the command line, open your Spacemacs directory by entering
cd ~/.emacs.dand then hittingRETURN. Once you are in the Spacemacs directory, entergit statusand then hitRETURNto know the current status (branch you are on, how many commits ahead or behind oforiginyou are etc.) of the repository. -
Type
M ato open themagitinterface to add a new remote. Type the Remote name asupstreamand Remote url as[email protected]:syl20bnr/spacemacs.git(orhttps://github.com/syl20bnr/spacemacs.gitif you're using HTTPS). Typenwhenmagitasks to set yourremote.pushDefaulttoupstream.From the command line, type
git remote add -f upstream [email protected]:syl20bnr/spacemacs.gitto achieve the same effect as above.
As it can happen from time-to-time, your fork of Spacemacs (which we will refer to as origin) can go out-of-sync with upstream. You need to ensure that you consistently keep updating from upstream.
-
Open
magit-statusfor~/emacs.dusing the same sequence of steps detailed in the above section. -
Switch to the
developbranch, if you are not already there. Hitb band typedevelop. If you haven't previously checked out thedevelopbranch, instead ofb b(or, branch checkout), you will need to typeb c(or, create and checkout). It will prompt you for the branch to base it off of, select or typeorigin/develop, hitRETURNand then name the branchdevelop. Note that any time in themagit-statusbuffer, if you want to know what commands are available, just hit?.From the command line, you can type
git checkout developto check out thedevelopbranch. If you haven't checked it out before, typegit checkout -b develop origin/developto check out a localdevelopbranch based off of theorigin/developbranch. -
After you have the
developbranch checked out, update it against the remoteupstreamrepository. HitFfor Pulling. Then typerto rebase. Even though we don't yet have any local commits, it makes sense to rebase any unpushed commits on the remote branch so that they are up to date and can be merged without merge commits. Hiteto pull and rebase from elsewhere. Typeupstream/developin the subsequent popup to pull rebase fromupstream.From the command line, type
git pull --rebase upstream developto achieve the same effect as above.After this is done, we want to restart Emacs to run any of the latest changes. Hit
SPC q rto restart Emacs. -
You will also need to push the newly rebased changes to your fork (
originrepository) on Github. To do this, typePin themagit-statusbuffer. Then typeuto push toorigin/develop.From the command line, type
git push origin developto achieve the same effect.
Before any changes are made, you need to make a branch to put them in. You could just commit to the develop branch, push your changes to your fork, and then do a pull request off of that. However, this is not recommended since it is common to have multiple pull requests open at one time. Therefore it is simpler to do a branch per pull request. This also allows your branches to have meaningful names, and makes updating pull requests with maintainer feedback a much simpler process.
-
From the
magit-statusbuffer, hitb c(or, create and checkout branch). -
Magit will then prompt you for the branch you are branching off of. Choose
develop. -
Next, it will prompt you for a branch name. Seeing as git doesn't restrict branch names to a particular length, you can go for long descriptive names (like
fix/spacemacs-home-buffer-bookmarks-jump) if you so desire.
From the command line, type git checkout -b fix/spacemacs-home-buffer-bookmarks-jump develop to achieve the same result as above.
Check out the Git book chapter on branching for an in-depth discussion of branching.
Now that we have a branch we can make your changes. Go ahead and make the changes you want. After you have tested and are satisfied with them, you are ready to commit and push.
-
Go to the
magit-statusbuffer again:SPC u SPC g s ~/.emacs.d RET.On the command line, you can type
git statusto see a list of all the changes you have made to existing files or to see any new files that have been added. -
Stage any unstaged changes you have made. Quickly: hit
son each line under Unstaged changes corresponding to a file you've changed. If you have added any new files, they will appear under Untracked files. Be sure to stage them as well by pressings.From the command line, type
git add <FULL PATH TO FILE>to stage the changes. You can then typegit diff --cachedto see a diff of all the staged changes to verify whether everything is in order. -
Hit
c cto commit all staged changes. -
Type a meaningful commit message. (See this post for a great explanation of what a good commit message is.) Helpfully, the diff of what you have changed is shown on the right-hand side for you to see what you did. Make the first line be a short subject describing the commit. Add a blank line and then in lines wrapped at 78, write a brief description of the changes and why. If you are fixing an issue that has been filed, include something along the lines of 'Fixes #2431'. Hit
C-c C-c(that's Control and c together, and then again).On the command line, type
git commitand pressRETURN. This will open a Vim interface where you can enter your commit message as detailed above. Then you can press:wqto commit your changes. -
Hit
P(or, Pushing). Typeuto set theremotebranch and push. Start typingorigin/fix/spacemacsand it will finish the branch name for you --origin/fix/spacemacs-home-buffer-bookmarks-jump. HitRETURN.From the command line, type
git push origin fix/spacemacs-home-buffer-bookmarksto push your changes to your fork.
You are now ready to submit your pull request. Switch back to your browser to the page for your fork.
-
Github will show your recently pushed branches near the top, in a yellow box. Refresh your page if you don't see this. Click the green "Compare & pull request" button.
-
In the next screen, Github will prompt you for a branch to compare against. By default it will show base: master. You want to select
develophere. It may take a minute for the page to update after you have selected thedevelopbranch. -
If you've done everything right, it will be able to cleanly merge your commit and will indicate so. It will then pull from your commit message the subject and description. If you've written a good commit message, there should be no need to add anything here. Click Create pull request.
Congratulations! There you go, you have created your first pull request. Hopefully the project developers will like your pull request and merge it.
As is often the case, the maintainers might offer feedback on your pull request that will require changes to be made.
-
Go to the
magit-statusbuffer again:SPC u SPC g s ~/.emacs.d RET. -
Check out your existing
fix/spacemacs-home-buffer-bookmarks-jumpbranch (or whatever it is you named your branch when creating it) by typingb band thenfix/spacemacs-home-buffer-bookmarks-jump. -
Make your changes as you did before.
-
Instead of creating a new commit with the changes, you can amend the existing commit. First type
cfrom themagit-statusbuffer. Then typeawhich will open up the same commit buffer as before. Your existing commit message should already be pre-filled in the buffer. You can choose to modify it or commit with the same message by typingC-c C-cas before.From the command line, type
git commit --amendto achieve the same result as above. -
It is advised to ensure your
fix/spacemacs-home-buffer-bookmarks-jumpbranch is up-to-date withupstream/developbefore updating the pull request. This can be done by typingFin themagit-statusbuffer, then typingr, followed bye. In the popup that appears, typeupstream/developto rebase your current branch with changes fromupstream/develop. This will pull all changes fromupstream/develop, first apply them locally, and then apply your most recent commit from the above step on top of it.From the command line, type
git pull --rebase upstream developfor the same result. -
Push your changes to
origin. TypeP, followed by-force, followed byuto push our changes. Note: Since we've updated an existing commit, we need to force push our changes. Otherwise, they will be rejected by Github.From the command line, type
git push -f origin fix/spacemacs-home-buffer-bookmarks-jumpfor the same result.
Happy Hacking!