You already have your own forked copy of the NumPy repository, have configured
Git, and have linked the upstream repository as explained in
Linking your repository to the upstream repo. What is described below is a recommended workflow
with Git.
Basic workflow
In short:
Start a new feature branch for each set of edits that you do.
See below.
Contributors: push your feature branch to your own Github repo, and
create a pull request.
Core developers: If you want to push changes without
further review, see the notes below.
This way of working helps to keep work well organized and the history
as clear as possible.
Making a new feature branch
First, fetch new commits from the upstream repository:
gitfetchupstream
Then, create a new branch based on the main branch of the upstream
repository:
gitcheckout-bmy-new-featureupstream/main
The editing workflow
Overview
# hack hackgitstatus# Optionalgitdiff# Optionalgitaddmodified_filegitcommit# push the branch to your own Github repogitpushoriginmy-new-feature
In more detail
Make some changes. When you feel that you’ve made a complete, working set
of related changes, move on to the next steps.
Optional: Check which files have changed with gitstatus. You’ll see a
listing like this one:
# On branch my-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)## INSTALLnochangesaddedtocommit(use"git add"and/or"git commit -a"
Optional: Compare the changes with the previous version using with gitdiff. This brings up a simple text browser interface that
highlights the difference between your files and the previous version.
Add any relevant modified or new files using gitaddmodified_file.
This puts the files into a staging area, which is a queue
of files that will be added to your next commit. Only add files that have
related, complete changes. Leave files with unfinished changes for later
commits.
To commit the staged files into the local copy of your repo, do gitcommit. At this point, a text editor will open up to allow you to write a
commit message. Read the commit message
section to be sure that you are writing a
properly formatted and sufficiently detailed commit message. After saving
your message and closing the editor, your commit will be saved. For trivial
commits, a short commit message can be passed in through the command line
using the -m flag. For example, gitcommit-am"ENH:Somemessage".
In some cases, you will see this form of the commit command: gitcommit-a. The extra -a flag automatically commits all modified files and
removes all deleted files. This can save you some typing of numerous gitadd commands; however, it can add unwanted changes to a commit if you’re
not careful.
Push the changes to your fork on GitHub:
gitpushoriginmy-new-feature
It may be the case that while you were working on your edits, new commits have
been added to upstream that affect your work. In this case, follow the
Rebasing on main section of this document to apply those changes to
your branch.
Writing the commit message
Commit messages should be clear and follow a few basic rules. Example:
If you plan a new feature or API change, it’s wisest to first email the
NumPy mailing list
asking for comment. If you haven’t heard back in a week, it’s
OK to ping the list again.
Asking for your changes to be merged with the main repo
When you feel your work is finished, you can create a pull request (PR).
If your changes involve modifications to the API or addition/modification of a
function, add a release note to the doc/release/upcoming_changes/
directory, following the instructions and format in the
doc/release/upcoming_changes/README.rst file.
Use the same prefix convention for your pull request title as for commit
messages (e.g., BUG:, ENH:, DOC:). This enables automated labeling
of your PR.
Getting your PR reviewed
We review pull requests as soon as we can, typically within a week. If you get
no review comments within two weeks, feel free to ask for feedback by
adding a comment on your PR (this will notify maintainers).
If your PR is large or complicated, asking for input on the numpy-discussion
mailing list may also be useful.
Rebasing on main
This updates your feature branch with changes from the upstream NumPy
GitHub repo. If you do not absolutely need to do this, try to avoid doing
it, except perhaps when you are finished. The first step will be to update
the remote repository with new commits from upstream:
gitfetchupstream
Next, you need to update the feature branch:
# go to the feature branchgitcheckoutmy-new-feature# make a backup in case you mess upgitbranchtmpmy-new-feature# rebase on upstream main branchgitrebaseupstream/main
If you have made changes to files that have changed also upstream,
this may generate merge conflicts that you need to resolve. See
below for help in this case.
Finally, remove the backup branch upon a successful rebase:
gitbranch-Dtmp
Recovering from mess-ups
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:
gitrebase--abort
If you notice you messed up after the rebase:
# reset branch back to the saved pointgitreset--hardtmp
If you forgot to make a backup branch:
# look at the reflog of the branchgitreflogshowmy-feature-branch8630830my-feature-branch@{0}:commit:BUG:io:closefilehandlesimmediately278dd2amy-feature-branch@{1}:rebasefinished:refs/heads/my-feature-branchonto11ee694744f2552d26aa21amy-feature-branch@{2}:commit:BUG:lib:makeseek_gzip_factorynotleakgzipobj...# reset the branch to where it was before the botched rebasegitreset--hardmy-feature-branch@{2}
If you didn’t actually mess up but there are merge conflicts, you need to
resolve those.
Additional things you might want to do
Rewriting commit history
There’s an embarrassing typo in a commit you made? Or perhaps you
made several false starts you would like the posterity not to see.
and 6ad92e5 is the last commit in the main branch. Suppose we
want to make the following changes:
Rewrite the commit message for 13d7934 to something more sensible.
Combine the commits 2dec1ac, a815645, eadc391 into a single one.
We do as follows:
# make a backup of the current stategitbranchtmpHEAD# interactive rebasegitrebase-i6ad92e5
This will open an editor with the following text in it:
pick13d7934Firstimplementationpick2dec1acFixafewbugs+disablepicka815645Modifyitsothatitworkspickeadc391Fixsomeremainingbugs# Rebase 6ad92e5..eadc391 onto 6ad92e5## Commands:# p, pick = use commit# r, reword = use commit, but edit the commit message# e, edit = use commit, but stop for amending# s, squash = use commit, but meld into previous commit
To achieve what we want, we will make the following changes to it:
This means that (i) we want to edit the commit message for
13d7934, 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, we get the output:
If you want to work on some stuff with other people, where you are all
committing into the same repository, or even the same branch, then just
share it via GitHub.
Then, go to your forked repository github page, say
https://github.com/your-user-name/numpy
Click on the ‘Admin’ button, and add anyone else to the repo as a
collaborator:
Now all those people can do:
gitclonegit@github.com:your-user-name/numpy.git
Checkout changes from an existing pull request
If you want to test the changes in a pull request or continue the work in a
new pull request, the commits are to be cloned into a local branch in your
forked repository
Then, fetch the changes and create a local branch. Assuming $ID is the pull request number
and $BRANCHNAME is the name of the new local branch you wish to create:
git fetch upstream pull/$ID/head:$BRANCHNAME
Checkout the newly created branch:
git checkout $BRANCHNAME
You now have the changes in the pull request.
Exploring your repository
To see a graphical representation of the repository branches and
commits:
gitk--all
To see a linear list of commits for this branch:
gitlog
Backporting
Backporting is the process of copying new feature/fixes committed in NumPy’s
main branch back to stable release branches. To do this you make a branch
off the branch you are backporting to, cherry pick the commits you want from
numpy/main, and then submit a pull request for the branch containing the
backport.
First, you need to make the branch you will work on. This needs to be
based on the older version of NumPy (not main):
# Make a new branch based on numpy/maintenance/1.8.x,# backport-3324 is our new name for the branch.gitcheckout-bbackport-3324upstream/maintenance/1.8.x
Pushing changes to the main repo
Requires commit rights to the main NumPy repo.
When you have a set of “ready” changes in a feature branch ready for
NumPy’s main or maintenance branches, you can push
them to upstream as follows:
First, merge or rebase on the target branch.
Only a few, unrelated commits then prefer rebasing:
You have to use --set-upstream for each new branch that you create.
of
commit
this
is
.
Then
a
blank
line
,
then
more
text
if
needed
.
Lines
shouldn
't be longer than 72
characters
.
If
the
commit
is
related
to
a
ticket
,
indicate
that
with
"See #3456"
,
"See ticket 3456"
,
"Closes #3456"
or
similar
.
Describing the motivation for a change, the nature of a bug for bug fixes or
some details on what an enhancement does are also good to include in a commit
message. Messages should be understandable without looking at the code
changes. A commit message like MAINT:fixedanotherone is an example of
what not to do; the reader has to go look for context elsewhere.
Standard acronyms to start the commit message with are:
By default a lot of continuous integration (CI) jobs are run for every PR,
from running the test suite on different operating systems and hardware
platforms to building the docs. In some cases you already know that CI isn’t
needed (or not all of it), for example if you work on CI config files, text in
the README, or other files that aren’t involved in regular build, test or docs
sequences. In such cases you may explicitly skip CI by including one or more of
these fragments in each commit message of a PR:
[skipci]: skip all CI
Only recommended if you are still not ready for the checks to run on your PR
(for example, if this is only a draft.)
[skipactions]: skip GitHub Actions jobs
GitHub Actions is where most of the CI
checks are run, including the linter, benchmarking, running basic tests for
most architectures and OSs, and several compiler and CPU optimization
settings.
See the configuration files for these checks.
[skipcircle]: skip CircleCI jobs
CircleCI is where we build the documentation and
store the generated artifact for preview in each PR. This check will also run
all the docstrings examples and verify their results. If you don’t make
documentation changes, but you make changes to a function’s API, for example,
you may need to run these tests to verify that the doctests are still valid.
See the configuration file for these checks.
Numpy currently uses cibuildwheel
in order to build wheels through continuous integration services. To save resources, the
cibuildwheel wheel builders are not run by default on every single PR or commit to main.
If you would like to test that your pull request do not break the wheel builders,
you can do so by appending [wheelbuild] to the first line of the commit
message of the newest commit in your PR. Please only do so for build-related
PRs, because running all wheel builds is slow and expensive.
The wheels built via github actions (including 64-bit Linux, x86-64 macOS, and
32/64-bit Windows) will be uploaded as artifacts in zip files. You can access
them from the Summary page of the “Wheel builder” action. The aarch64 Linux and
arm64 macOS wheels built via Cirrus CI are not available as artifacts.
Additionally, the wheels will be uploaded to
https://anaconda.org/scientific-python-nightly-wheels/ on the following conditions:
by a weekly cron job or
if the GitHub Actions or Cirrus build has been manually triggered, which
requires appropriate permissions
# f, fixup = like "squash", but discard this commit's log message
#
# If you remove a line here THAT COMMIT WILL BE LOST.
# However, if you remove everything, the rebase will be aborted.
#
changed
,
79
insertions
(
+
),
61
deletions
(
-
)
Successfully
rebased
and
updated
refs
/
heads
/
my
-
feature
-
branch
.
Remember that links starting with git@ use the ssh protocol and are
read-write; links starting with git:// are read-only.
Your collaborators can then commit directly into that repo with the
usual:
gitcommit-am'ENH - much better code'gitpushoriginmy-feature-branch# pushes directly into your repo
Now you need to apply the changes from main to this branch using
gitcherry-pick:
# Update remotegitfetchupstream# Check the commit log for commits to cherry pickgitlogupstream/main# This pull request included commits aa7a047 to c098283 (inclusive)# so you use the .. syntax (for a range of commits), the ^ makes the# range inclusive.gitcherry-pickaa7a047^..c098283...# Fix any conflicts, then if needed:gitcherry-pick--continue
You might run into some conflicts cherry picking here. These are
resolved the same way as merge/rebase conflicts. Except here you can
use gitblame to see the difference between main and the
backported branch to make sure nothing gets screwed up.
Push the new branch to your Github repository:
gitpush-uoriginbackport-3324
Finally make a pull request using Github. Make sure it is against the
maintenance branch and not main, Github will usually suggest you
make the pull request against main.
If all of the commits are related, create a merge commit:
gitfetchupstreamgitmerge--no-ffupstream/main
Check that what you are going to push looks sensible: