To keep your work well organized, with readable history, and in turn make it
easier for project maintainers (that might be you) to see what you've done, and
why you did it, we recommend the following:
Don't make changes in your local main branch!
Before starting a new set of changes, fetch all changes from
upstream/main, and start a new feature branch from that.
Make a new branch for each feature or bug fix — "one task, one branch".
Name your branch for the purpose of the changes - e.g.
bugfix-for-issue-14 or refactor-database-code.
When you're ready or need feedback on your code, open a pull request so that the
Matplotlib developers can give feedback and eventually include your suggested
code into the branch.
From time to time you should fetch the upstream changes from GitHub:
git fetch upstream
This will pull down any commits you don't have, and set the remote branches to
point to the right commit.
Make a new feature branch
When you are ready to make some changes to the code, you should start a new
branch. Branches that are for a collection of related edits are often called
'feature branches'. Making a new branch for each set of related changes will make it
easier for someone reviewing your branch to see what you are doing.
Choose an informative name for the branch to remind yourself and the rest of us
what the changes in the branch are for. For example add-ability-to-fly, or
bugfix-for-issue-42.
The process for creating a new feature branch is:
# Update the main branch
gitfetchupstream
# Make new feature branch starting at current main
gitbranchmy-new-featureupstream/main
gitcheckoutmy-new-feature
If you started making changes on your local main branch, you can convert the
branch to a feature branch by renaming it:
git branch -m <newname>
Generally, you will want to keep your feature branches on your public GitHub
fork of Matplotlib. To do this, you gitpush this new branch up to your
GitHub repo. Generally, if you followed the instructions in these pages, and by
default, git will have a link to your fork of the GitHub repo, called
origin. You push up to your own fork with:
git push origin my-new-feature
The editing workflow
Make some changes
Save the changes
See which files have changed with gitstatus.
You'll see a listing like this one:
# On branch ny-new-feature
# Changed but not updated:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: README
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# INSTALL
no changes added to commit (use "git add" and/or "git commit -a")
Check what the actual changes are with gitdiff.
Add any new files to version control gitaddnew_file_name.
To commit all modified files into the local copy of your repo, type:
gitcommit-am'A commit message'
Note the -am options to commit. The m flag signals that you are
going to type a message on the command line. The a flag stages every
file that has been modified, except files listed in .gitignore. For more
information, see the git commit manual page.
To push the changes up to your forked repo on GitHub, do a gitpush.
Verify your changes
Check that your change does what you intend. For code changes:
If the issue you are working on provided a code example, run that example
against your branch and check that you now get the desired result. Note that
adapting the issue example is often a good way to create a new test.
Run the tests to check that your change has not had unintended consequences
on existing functionality. See Running the tests.
For documentation changes, build the documentation locally to check that
it renders how you intended and that any new links work correctly. See
Build the docs.
This is also a good time to look through the Summary for pull request authors and
address as many of the relevant points as you can.
Go to the web page of your fork of the Matplotlib repo, and click
Compare&pullrequest to send your changes to the maintainers for review.
The base repository is matplotlib/matplotlib and the base branch is
generally main.
Enter a title for the set of changes with some explanation of what you've done.
Mention anything you'd like particular attention for - such as a
complicated change or some code you are not happy with.
If you don't think your request is ready to be merged, make a
draft pull request and state what aspects you want to have
feedback on. This is a good way of getting some preliminary code review.
For more guidance on the mechanics of making a pull request, see GitHub's
pull request tutorial.
Update a pull request
When updating your pull request after making revisions, instead of adding new
commits, please consider amending your initial commit(s) to keep the commit
history clean.
To see a graphical representation of the repository branches and
commits:
gitk --all
To see a linear list of commits for this branch:
git log
Recover from mistakes
Sometimes, you mess up merges or rebases. Luckily, in git it is
relatively straightforward to recover from such mistakes.
If you mess up during a rebase:
git rebase --abort
If you notice you messed up after the rebase:
# reset branch back to the saved point
gitreset--hardtmp
If you forgot to make a backup branch:
# look at the reflog of the branch
gitreflogshowmy-new-feature
8630830my-new-feature@{0}:commit:BUG:io:closefilehandlesimmediately
278dd2amy-new-feature@{1}:rebasefinished:refs/heads/my-new-featureonto11ee694744f2552d
26aa21amy-new-feature@{2}:commit:BUG:lib:makeseek_gzip_factorynotleakgzipobj
...
# reset the branch to where it was before the botched rebase
gitreset--hardmy-new-feature@{2}
Rewrite commit history
Is there an embarrassing typo in a commit you made? Or perhaps you
made several false starts you don't want posterity to see.
Let's say you thought of some work you'd like to do. You
Update the main branch and Make a new feature branch called
my-new-feature. At this stage, main is at some commit, let's call it E.
Now you make some new commits on your my-new-feature branch, let's call them
A, B, C. Maybe your changes take a while, or you come back to them after a
while. In the meantime, main has progressed from commit E to commit (say) G:
A---B---C my-new-feature
/
D---E---F---G main
At this stage you consider merging main into your feature branch, and you
remember that this page sternly advises you not to do that, because the
history will get messy. Most of the time, you can just ask for a review without
worrying about whether has got a little ahead; however sometimes, the changes in
might affect your changes, and you need to harmonize them. In this
situation you may prefer to do a rebase.
where you have pushed the commits A,B,C to your fork on GitHub (under the
remote name origin) but now have the commits A' and E on your local
branch my-new-feature. If you try to push the new commits to GitHub, it will
fail and show an error that looks like
Whenever a pull request is created or updated, various automated test tools
will run on all supported platforms and versions of Python.
tox is not used in the automated testing. It is supported for testing
locally.
Codecov and CodeQL are currently for information only. Their failure is not
necessarily a blocker.
Make sure the Linting, GitHub Actions, AppVeyor, CircleCI, and Azure pipelines are
passing before merging. All checks are listed at the bottom of the GitHub page of your
pull request.
Search the log for FAILURES. Subsequent section should contain information
on failed tests.
On Azure, find the images as artifacts of the Azure job:
1. Click Details on the check on the GitHub PR page.
2. Click View more details on Azure Pipelines to go to Azure.
3. On the overview page artifacts are listed in the section Related.
Skip CI checks
If you know only a subset of CI checks need to be run, you can skip unneeded CI checks
on individual commits by including the following strings in the commit message:
String
Effect
Notes
[cidoc]
Only run documentation checks.
For when you have only changed documentation.
(
)
#30778 from timhoffm/decorator-tracebackhide
#30838 from has2k1/fix-numpy-integer-markers
and b7e99a8659 is the most recent commit in the my-new-feature branch. Suppose we
want to make the following changes:
Rewrite the commit message for 9a5d1ca186 to something more specific.
Combine the commits 34448c69eb, 8a5de78b17, b7e99a8659 into a single one.
We do as follows:
# make a backup of the current state
gitbranchtmpHEAD
# interactive rebase
gitrebase-id1da6fbf0b
This will open an editor with the following text in it:
pick9a5d1ca186Firstimplementation
pick34448c69ebFixafewbugs+disable
pick8a5de78b17Modifyitsothatitworks
pickb7e99a8659Fixsomeremainingbugs
# Rebase d1da6fbf0b..b7e99a8659 onto d1da6fbf0b (4 commands)## Commands:# p, pick <commit> = use commit# r, reword <commit> = use commit, but edit the commit message# e, edit <commit> = use commit, but stop for amending# s, squash <commit> = use commit, but meld into previous commit# f, fixup [-C | -c] <commit> = like "squash" but keep only the previous# commit's log message, unless -C is used, in which case# keep only this commit's message; -c is same as -C but# opens the editor# x, exec <command> = run command (the rest of the line) using shell# b, break = stop here (continue rebase later with 'git rebase --continue')# d, drop <commit> = remove commit# l, label <label> = label current HEAD with a name# t, reset <label> = reset HEAD to a label# m, merge [-C <commit> | -c <commit>] <label> [# <oneline>]# create a merge commit using the original merge commit's# message (or the oneline, if no original merge commit was# specified); use -c <commit> to reword the commit message# u, update-ref <ref> = track a placeholder for the <ref> to be updated# to this position in the new commits. The <ref> is# updated at the end of the rebase## These lines can be re-ordered; they are executed from top to bottom.## If you remove a line here THAT COMMIT WILL BE LOST.## However, if you remove everything, the rebase will be aborted.#
To achieve what we want, we will make the following changes to it:
r 9a5d1ca186 First implementation
pick 34448c69eb Fix a few bugs + disable
f 8a5de78b17 Modify it so that it works
f b7e99a8659 Fix some remaining bugs
This means that (i) we want to edit the commit message for
9a5d1ca186, and (ii) collapse the last three commits into one. Now we
save and quit the editor.
Git will then immediately bring up an editor for editing the commit
message. After revising it, the history looks like this:
955f532b04(HEAD->my-new-feature)Fixafewbugs+disable
5a2046b5a7Addmycoolestoffeatures
d1da6fbf0b(upstream/main)Mergepullrequest#30778 from timhoffm/decorator-tracebackhide
6ad937ad83Mergepullrequest#30838 from has2k1/fix-numpy-integer-markers
...
If it went wrong, recovery is again possible as explained above.
If you have not yet pushed this branch to github, you can carry on as normal,
however if you have already pushed this commit see Push with force for how
to replace your already published commits with the new ones.
main
main
rebase takes your changes (A, B, C) and replays them as if they had been
made to the current state of main. In other words, in this case, it takes
the changes represented by A, B, C and replays them on top of G. After the
rebase, your history will look like this:
# Fetch changes from upstream/main
gitfetchupstream
# go to the feature branch
gitcheckoutmy-new-feature
# make a backup in case you mess up
gitbranchtmpmy-new-feature
# rebase my-new-feature onto main
gitrebase--ontoupstream/mainupstream/mainmy-new-feature
In this situation, where you are already on branch my-new-feature, the last
command can be written more succinctly as:
git rebase upstream/main
When all looks good, you can delete your backup branch:
If you have made changes to files that have also changed in main, this may
generate merge conflicts that you need to resolve - see the git rebase man
page for some instructions at the end of the "Description" section. There is
some related help on merging in the git user manual - see resolving a merge.
If you have not yet pushed this branch to github, you can carry on as normal,
however if you have already pushed this commit see Push with force for how
to replace your already published commits with the new ones.
[
]
(
)
'github.com:origin/matplotlib.git'
(
'git pull ...'
)
'Note about fast-forwards'
in
'git push --help'
for
If this push had succeeded, the commits A, B, and C would no
longer be referenced by any branch and they would be discarded:
D---A'---E my-new-feature, origin/my-new-feature
By default gitpush helpfully tries to protect you from accidentally
discarding commits by rejecting the push to the remote. When this happens,
GitHub also adds the helpful suggestion to pull the remote changes and then try
pushing again. In some cases, such as if you and a colleague are both
committing and pushing to the same branch, this is a correct course of action.
However, in the case of having intentionally re-written history, we want to
discard the commits on the remote and replace them with the new-and-improved
versions from our local branch. In this case, what we want to do is
$ git push --force-with-lease
which tells git you are aware of the risks and want to do the push anyway. We
recommend using --force-with-lease over the --force flag. The
--force will do the push no matter what, whereas --force-with-lease
will only do the push if the remote branch is where the local git client
thought it was.
Be judicious with force-pushing. It is effectively re-writing published
history, and if anyone has fetched the old commits, it will have a different view
of history which can cause confusion.
[cidoc] is applied automatically when the changes are only to files in
doc/**/ or galleries/**/
[skipdoc]
Skip documentation checks.
For when you didn't change documentation.
[skipappveyor]
Skip AppVeyor run.
Substring must be in first line of commit message.
[skipazp]
Skip Azure Pipelines.
[skipactions]
Skip GitHub Actions.
[skipci]
Skip all CI checks.
Use only for changes where documentation checks and unit tests do not apply.
[skipactions] and [skipci] only skip Github Actions CI workflows that are
triggered on on:push and on:pull_request events. For more information,
see Skipping workflow runs.