2023-01-12 20:49:14 +01:00
|
|
|
|
2022-03-18 17:46:08 +01:00
|
|
|
|
2024-05-04 00:04:16 +02:00
|
|
|
# Pull request workflow
|
2022-03-18 17:46:08 +01:00
|
|
|
|
2024-03-16 20:56:52 +01:00
|
|
|
The so-called "PR workflow" used by Pandemonium is common to many projects using
|
2022-03-18 17:46:08 +01:00
|
|
|
Git, and should be familiar to veteran free software contributors. The idea
|
|
|
|
is that only a small number (if any) commit directly to the *master* branch.
|
|
|
|
Instead, contributors *fork* the project (i.e. create a copy of it, which
|
|
|
|
they can modify as they wish), and then use the GitHub interface to request
|
|
|
|
a *pull* from one of their fork's branches to one branch of the original
|
|
|
|
(often named *upstream*) repository.
|
|
|
|
|
|
|
|
The resulting *pull request* (PR) can then be reviewed by other contributors,
|
|
|
|
which might approve it, reject it, or most often request that modifications
|
|
|
|
be done. Once approved, the PR can then be merged by one of the core
|
|
|
|
developers, and its commit(s) will become part of the target branch (usually
|
|
|
|
the *master* branch).
|
|
|
|
|
|
|
|
We will go together through an example to show the typical workflow and
|
|
|
|
associated Git commands. But first, let's have a quick look at the
|
2024-03-16 20:56:52 +01:00
|
|
|
organization of Pandemonium's Git repository.
|
2022-03-18 17:46:08 +01:00
|
|
|
|
2024-05-04 00:04:16 +02:00
|
|
|
## Git source repository
|
2022-03-18 17:46:08 +01:00
|
|
|
|
2024-03-16 21:04:42 +01:00
|
|
|
The `repository on GitHub ( https://github.com/Relintai/pandemonium_engine )` is a
|
2023-01-12 20:57:31 +01:00
|
|
|
`Git ( https://git-scm.com )` code repository together with an embedded
|
2022-03-18 17:46:08 +01:00
|
|
|
issue tracker and PR system.
|
|
|
|
|
2023-01-12 20:55:57 +01:00
|
|
|
Note:
|
|
|
|
If you are contributing to the documentation, its repository can
|
2024-03-16 21:04:42 +01:00
|
|
|
be found `here ( https://github.com/Relintai/pandemonium_engine-docs )`.
|
2022-03-18 17:46:08 +01:00
|
|
|
|
|
|
|
The Git version control system is the tool used to keep track of successive
|
2024-03-16 20:56:52 +01:00
|
|
|
edits to the source code - to contribute efficiently to Pandemonium, learning the
|
2022-03-18 17:46:08 +01:00
|
|
|
basics of the Git command line is *highly* recommended. There exist some
|
|
|
|
graphical interfaces for Git, but they usually encourage users to take bad
|
|
|
|
habits regarding the Git and PR workflow, and we therefore recommend not to
|
|
|
|
use them. In particular, we advise not to use GitHub's online editor for code
|
|
|
|
contributions (although it's tolerated for small fixes or documentation changes)
|
|
|
|
as it enforces one commit per file and per modification,
|
|
|
|
which quickly leads to PRs with an unreadable Git history (especially after peer review).
|
|
|
|
|
2023-01-12 20:55:57 +01:00
|
|
|
See also:
|
|
|
|
The first sections of Git's "Book" are a good introduction to
|
2022-03-18 17:46:08 +01:00
|
|
|
the tool's philosophy and the various commands you need to
|
|
|
|
master in your daily workflow. You can read them online on the
|
2023-01-12 20:57:31 +01:00
|
|
|
`Git SCM ( https://git-scm.com/book/en/v2 )` website.
|
2023-01-12 20:39:50 +01:00
|
|
|
You can also try out `GitHub's interactive guide ( https://try.github.io/ )`.
|
2022-03-18 17:46:08 +01:00
|
|
|
|
|
|
|
The branches on the Git repository are organized as follows:
|
|
|
|
|
2023-01-12 19:43:03 +01:00
|
|
|
- The `master` branch is where the development of the next major version
|
2022-03-18 17:46:08 +01:00
|
|
|
occurs. As a development branch, it can be unstable
|
|
|
|
and is not meant for use in production. This is where PRs should be done
|
|
|
|
in priority.
|
2023-01-12 19:43:03 +01:00
|
|
|
- The stable branches are named after their version, e.g. `3.1` and `2.1`.
|
|
|
|
They are used to backport bugfixes and enhancements from the `master`
|
2022-03-18 17:46:08 +01:00
|
|
|
branch to the currently maintained stable release (e.g. 3.1.2 or 2.1.6).
|
|
|
|
As a rule of thumb, the last stable branch is maintained until the next
|
2023-01-12 19:43:03 +01:00
|
|
|
minor version (e.g. the `3.0` branch was maintained until the release of
|
2024-03-16 20:56:52 +01:00
|
|
|
Pandemonium 3.1).
|
2022-03-18 17:46:08 +01:00
|
|
|
If you want to make PRs against a maintained stable branch, please check
|
2023-01-12 19:43:03 +01:00
|
|
|
first if your changes are also relevant for the `master` branch, and if so
|
|
|
|
make the PR for the `master` branch in priority. Release managers can then
|
2022-03-18 17:46:08 +01:00
|
|
|
cherry-pick the fix to a stable branch if relevant.
|
|
|
|
- There might occasionally be feature branches, usually meant to be merged into
|
2023-01-12 19:43:03 +01:00
|
|
|
the `master` branch at some time.
|
2022-03-18 17:46:08 +01:00
|
|
|
|
2024-05-04 00:04:16 +02:00
|
|
|
## Forking and cloning
|
2022-03-18 17:46:08 +01:00
|
|
|
|
2024-03-16 21:04:42 +01:00
|
|
|
The first step is to *fork* the `pandemoniumengine/pandemonium ( https://github.com/Relintai/pandemonium_engine )`
|
2022-03-18 17:46:08 +01:00
|
|
|
repository on GitHub. To do so, you will need to have a GitHub account and to
|
|
|
|
be logged in. In the top right corner of the repository's GitHub page, you
|
|
|
|
should see the "Fork" button as shown below:
|
|
|
|
|
2023-01-12 20:16:00 +01:00
|
|
|
![](img/github_fork_button.png)
|
2022-03-18 17:46:08 +01:00
|
|
|
|
|
|
|
Click it, and after a while you should be redirected to your own fork of the
|
2024-03-16 20:56:52 +01:00
|
|
|
Pandemonium repo, with your GitHub username as namespace:
|
2022-03-18 17:46:08 +01:00
|
|
|
|
2023-01-12 20:16:00 +01:00
|
|
|
![](img/github_fork_url.png)
|
2022-03-18 17:46:08 +01:00
|
|
|
|
|
|
|
You can then *clone* your fork, i.e. create a local copy of the online
|
|
|
|
repository (in Git speak, the *origin remote*). If you haven't already,
|
2023-01-12 20:57:31 +01:00
|
|
|
download Git from `its website ( https://git-scm.com )` if you're using Windows or
|
2022-03-18 17:46:08 +01:00
|
|
|
macOS, or install it through your package manager if you're using Linux.
|
|
|
|
|
2023-01-12 20:55:57 +01:00
|
|
|
Note:
|
|
|
|
If you are on Windows, open Git Bash to type commands. macOS and Linux users
|
2022-03-18 17:46:08 +01:00
|
|
|
can use their respective terminals.
|
|
|
|
|
|
|
|
To clone your fork from GitHub, use the following command:
|
|
|
|
|
2023-01-12 22:00:14 +01:00
|
|
|
```
|
2024-05-04 14:08:00 +02:00
|
|
|
$ git clone https://github.com/USERNAME/pandemonium
|
2023-01-12 22:00:14 +01:00
|
|
|
```
|
2022-03-18 17:46:08 +01:00
|
|
|
|
2023-01-12 20:55:57 +01:00
|
|
|
Note:
|
|
|
|
In our examples, the "$" character denotes the command line prompt
|
2022-03-18 17:46:08 +01:00
|
|
|
on typical UNIX shells. It is not part of the command and should
|
|
|
|
not be typed.
|
|
|
|
|
2024-03-16 20:56:52 +01:00
|
|
|
After a little while, you should have a `pandemonium` directory in your current
|
2023-01-12 19:43:03 +01:00
|
|
|
working directory. Move into it using the `cd` command:
|
2022-03-18 17:46:08 +01:00
|
|
|
|
2023-01-12 22:00:14 +01:00
|
|
|
```
|
2024-05-04 14:08:00 +02:00
|
|
|
$ cd pandemonium
|
2023-01-12 22:00:14 +01:00
|
|
|
```
|
2022-03-18 17:46:08 +01:00
|
|
|
|
|
|
|
We will start by setting up a reference to the original repository that we forked:
|
|
|
|
|
2023-01-12 22:00:14 +01:00
|
|
|
```
|
2024-05-04 14:08:00 +02:00
|
|
|
$ git remote add upstream https://github.com/Relintai/pandemonium_engine
|
|
|
|
$ git fetch upstream
|
2023-01-12 22:00:14 +01:00
|
|
|
```
|
2022-03-18 17:46:08 +01:00
|
|
|
|
2023-01-12 19:43:03 +01:00
|
|
|
This will create a reference named `upstream` pointing to the original
|
2024-03-16 20:56:52 +01:00
|
|
|
`pandemoniumengine/pandemonium` repository. This will be useful when you want to pull new
|
2023-01-12 19:43:03 +01:00
|
|
|
commits from its `master` branch to update your fork. You have another
|
2024-03-16 20:56:52 +01:00
|
|
|
remote reference named `origin`, which points to your fork (`USERNAME/pandemonium`).
|
2022-03-18 17:46:08 +01:00
|
|
|
|
|
|
|
You only need to do the above steps once, as long as you keep that local
|
2024-03-16 20:56:52 +01:00
|
|
|
`pandemonium` folder (which you can move around if you want, the relevant
|
2023-01-12 19:43:03 +01:00
|
|
|
metadata is hidden in its `.git` subfolder).
|
2022-03-18 17:46:08 +01:00
|
|
|
|
2023-01-12 20:55:57 +01:00
|
|
|
Note:
|
|
|
|
*Branch it, pull it, code it, stage it, commit, push it, rebase
|
2022-03-18 17:46:08 +01:00
|
|
|
it... technologic.*
|
|
|
|
|
|
|
|
This bad take on Daft Punk's *Technologic* shows the general
|
|
|
|
conception Git beginners have of its workflow: lots of strange
|
|
|
|
commands to learn by copy and paste, hoping they will work as
|
|
|
|
expected. And that's actually not a bad way to learn, as long as
|
|
|
|
you're curious and don't hesitate to question your search engine
|
|
|
|
when lost, so we will give you the basic commands to know when
|
|
|
|
working in Git.
|
|
|
|
|
|
|
|
In the following, we will assume as an example that you want to implement a feature in
|
2024-03-16 20:56:52 +01:00
|
|
|
Pandemonium's project manager, which is coded in the `editor/project_manager.cpp`
|
2022-03-18 17:46:08 +01:00
|
|
|
file.
|
|
|
|
|
2024-05-04 00:04:16 +02:00
|
|
|
## Branching
|
2022-03-18 17:46:08 +01:00
|
|
|
|
2023-01-12 19:43:03 +01:00
|
|
|
By default, the `git clone` should have put you on the `master` branch of
|
|
|
|
your fork (`origin`). To start your own feature development, we will create
|
2022-03-18 17:46:08 +01:00
|
|
|
a feature branch:
|
|
|
|
|
2023-01-12 22:00:14 +01:00
|
|
|
```
|
2024-05-04 14:08:00 +02:00
|
|
|
# Create the branch based on the current branch (master)
|
|
|
|
$ git branch better-project-manager
|
2022-03-18 17:46:08 +01:00
|
|
|
|
2024-05-04 14:08:00 +02:00
|
|
|
# Change the current branch to the new one
|
|
|
|
$ git checkout better-project-manager
|
2023-01-12 22:00:14 +01:00
|
|
|
```
|
2022-03-18 17:46:08 +01:00
|
|
|
|
|
|
|
This command is equivalent:
|
|
|
|
|
2023-01-12 22:00:14 +01:00
|
|
|
```
|
2024-05-04 14:08:00 +02:00
|
|
|
# Change the current branch to a new named one, based on the current branch
|
|
|
|
$ git checkout -b better-project-manager
|
2023-01-12 22:00:14 +01:00
|
|
|
```
|
2022-03-18 17:46:08 +01:00
|
|
|
|
2023-01-12 19:43:03 +01:00
|
|
|
If you want to go back to the `master` branch, you'd use:
|
2022-03-18 17:46:08 +01:00
|
|
|
|
2023-01-12 22:00:14 +01:00
|
|
|
```
|
2024-05-04 14:08:00 +02:00
|
|
|
$ git checkout master
|
2023-01-12 22:00:14 +01:00
|
|
|
```
|
2022-03-18 17:46:08 +01:00
|
|
|
|
2023-01-12 19:43:03 +01:00
|
|
|
You can see which branch you are currently on with the `git branch`
|
2022-03-18 17:46:08 +01:00
|
|
|
command:
|
|
|
|
|
2023-01-12 22:00:14 +01:00
|
|
|
```
|
2024-05-04 14:08:00 +02:00
|
|
|
$ git branch
|
|
|
|
2.1
|
|
|
|
* better-project-manager
|
|
|
|
master
|
2023-01-12 22:00:14 +01:00
|
|
|
```
|
2022-03-18 17:46:08 +01:00
|
|
|
|
2023-01-12 19:43:03 +01:00
|
|
|
Be sure to always go back to the `master` branch before creating a new branch,
|
2022-03-18 17:46:08 +01:00
|
|
|
as your current branch will be used as the base for the new one. Alternatively,
|
|
|
|
you can specify a custom base branch after the new branch's name:
|
|
|
|
|
2023-01-12 22:00:14 +01:00
|
|
|
```
|
2024-05-04 14:08:00 +02:00
|
|
|
$ git checkout -b my-new-feature master
|
2023-01-12 22:00:14 +01:00
|
|
|
```
|
2022-03-18 17:46:08 +01:00
|
|
|
|
2024-05-04 00:04:16 +02:00
|
|
|
## Updating your branch
|
2022-03-18 17:46:08 +01:00
|
|
|
|
|
|
|
This would not be needed the first time (just after you forked the upstream
|
|
|
|
repository). However, the next time you want to work on something, you will
|
2023-01-12 19:43:03 +01:00
|
|
|
notice that your fork's `master` is several commits behind the upstream
|
|
|
|
`master` branch: pull requests from other contributors would have been merged
|
2022-03-18 17:46:08 +01:00
|
|
|
in the meantime.
|
|
|
|
|
|
|
|
To ensure there won't be conflicts between the feature you develop and the
|
2023-01-12 19:43:03 +01:00
|
|
|
current upstream `master` branch, you will have to update your branch by
|
2022-03-18 17:46:08 +01:00
|
|
|
*pulling* the upstream branch.
|
|
|
|
|
2023-01-12 22:00:14 +01:00
|
|
|
```
|
2024-05-04 14:08:00 +02:00
|
|
|
$ git pull --rebase upstream master
|
2023-01-12 22:00:14 +01:00
|
|
|
```
|
2022-03-18 17:46:08 +01:00
|
|
|
|
2023-01-12 19:43:03 +01:00
|
|
|
The `--rebase` argument will ensure that any local changes that you committed
|
2022-03-18 17:46:08 +01:00
|
|
|
will be re-applied *on top* of the pulled branch, which is usually what we want
|
|
|
|
in our PR workflow. This way, when you open a pull request, your own commits will
|
2023-01-12 19:43:03 +01:00
|
|
|
be the only difference with the upstream `master` branch.
|
2022-03-18 17:46:08 +01:00
|
|
|
|
|
|
|
While rebasing, conflicts may arise if your commits modified code that has been
|
|
|
|
changed in the upstream branch in the meantime. If that happens, Git will stop at
|
|
|
|
the conflicting commit and will ask you to resolve the conflicts. You can do so
|
|
|
|
with any text editor, then stage the changes (more on that later), and proceed with
|
2023-01-12 19:43:03 +01:00
|
|
|
`git rebase --continue`. Repeat the operation if later commits have conflicts too,
|
2022-03-18 17:46:08 +01:00
|
|
|
until the rebase operation completes.
|
|
|
|
|
|
|
|
If you're unsure about what is going on during a rebase and you panic (no worry,
|
2023-01-12 19:43:03 +01:00
|
|
|
we all do the first few times), you can abort the rebase with `git rebase --abort`.
|
2022-03-18 17:46:08 +01:00
|
|
|
You will then be back to the original state of your branch before calling
|
2023-01-12 19:43:03 +01:00
|
|
|
`git pull --rebase`.
|
2022-03-18 17:46:08 +01:00
|
|
|
|
2023-01-12 20:55:57 +01:00
|
|
|
Note:
|
|
|
|
If you omit the `--rebase` argument, you will instead create a merge
|
2022-03-18 17:46:08 +01:00
|
|
|
commit which tells Git what to make of the two distinct branches. If any
|
|
|
|
conflicts arise, they would be resolved all at once via this merge commit.
|
|
|
|
|
2023-01-12 19:43:03 +01:00
|
|
|
While this is a valid workflow and the default behavior of `git pull`,
|
2022-03-18 17:46:08 +01:00
|
|
|
merge commits within PRs are frowned upon in our PR workflow. We only use
|
|
|
|
them when merging PRs into the upstream branch.
|
|
|
|
|
|
|
|
The philosophy is that a PR should represent the final stage of the changes
|
|
|
|
made to the codebase, and we are not interested in mistakes and fixes that
|
|
|
|
would have been done in intermediate stages before merging.
|
|
|
|
Git gives us great tools to "rewrite the history" and make it as if we got
|
|
|
|
things right the first time, and we're happy to use it to ensure that
|
|
|
|
changes are easy to review and understand long after they have been merged.
|
|
|
|
|
2023-01-12 19:43:03 +01:00
|
|
|
If you have already created a merge commit without using `rebase`, or
|
2022-03-18 17:46:08 +01:00
|
|
|
have made any other changes that have resulted in undesired history, the best option
|
2023-01-12 19:29:11 +01:00
|
|
|
is to use an *interactive rebase* on the upstream branch. See the `dedicated
|
2023-01-12 20:47:54 +01:00
|
|
|
section ( doc_pr_workflow_rebase )` for instructions.
|
2022-03-18 17:46:08 +01:00
|
|
|
|
2023-01-12 21:01:51 +01:00
|
|
|
Tip:
|
|
|
|
If at any time you want to *reset* a local branch to a given commit or branch,
|
2023-01-12 20:47:54 +01:00
|
|
|
you can do so with `git reset --hard ( commit ID )` or
|
|
|
|
`git reset --hard ( remote>/( branch )` (e.g. `git reset --hard upstream/master`).
|
2022-03-18 17:46:08 +01:00
|
|
|
|
|
|
|
Be warned that this will remove any changes that you might have committed in
|
2023-01-12 19:43:03 +01:00
|
|
|
this branch. If you ever lose commits by mistake, use the `git reflog` command
|
2022-03-18 17:46:08 +01:00
|
|
|
to find the commit ID of the previous state that you would like to restore, and
|
2023-01-12 19:43:03 +01:00
|
|
|
use it as argument of `git reset --hard` to go back to that state.
|
2022-03-18 17:46:08 +01:00
|
|
|
|
2024-05-04 00:04:16 +02:00
|
|
|
## Making changes
|
2022-03-18 17:46:08 +01:00
|
|
|
|
|
|
|
You would then do your changes to our example's
|
2023-01-12 19:43:03 +01:00
|
|
|
`editor/project_manager.cpp` file with your usual development environment
|
2022-03-18 17:46:08 +01:00
|
|
|
(text editor, IDE, etc.).
|
|
|
|
|
|
|
|
By default, those changes are *unstaged*. The staging area is a layer between
|
|
|
|
your working directory (where you make your modifications) and the local Git
|
2023-01-12 19:43:03 +01:00
|
|
|
repository (the commits and all the metadata in the `.git` folder). To
|
2022-03-18 17:46:08 +01:00
|
|
|
bring changes from the working directory to the Git repository, you need to
|
2023-01-12 19:43:03 +01:00
|
|
|
*stage* them with the `git add` command, and then to commit them with the
|
|
|
|
`git commit` command.
|
2022-03-18 17:46:08 +01:00
|
|
|
|
|
|
|
There are various commands you should know to review your current work,
|
|
|
|
before staging it, while it is staged, and after it has been committed.
|
|
|
|
|
2023-01-12 19:43:03 +01:00
|
|
|
- `git diff` will show you the current unstaged changes, i.e. the
|
2022-03-18 17:46:08 +01:00
|
|
|
differences between your working directory and the staging area.
|
2023-01-12 20:47:54 +01:00
|
|
|
- `git checkout -- ( files )` will undo the unstaged changes to the given
|
2022-03-18 17:46:08 +01:00
|
|
|
files.
|
2023-01-12 20:47:54 +01:00
|
|
|
- `git add ( files )` will *stage* the changes on the listed files.
|
2023-01-12 19:43:03 +01:00
|
|
|
- `git diff --staged` will show the current staged changes, i.e. the
|
2022-03-18 17:46:08 +01:00
|
|
|
differences between the staging area and the last commit.
|
2023-01-12 20:47:54 +01:00
|
|
|
- `git reset HEAD ( files )` will *unstage* changes to the listed files.
|
2023-01-12 19:43:03 +01:00
|
|
|
- `git status` will show you what are the currently staged and unstaged
|
2022-03-18 17:46:08 +01:00
|
|
|
modifications.
|
2023-01-12 19:43:03 +01:00
|
|
|
- `git commit` will commit the staged files. It will open a text editor
|
|
|
|
(you can define the one you want to use with the `GIT_EDITOR` environment
|
|
|
|
variable or the `core.editor` setting in your Git configuration) to let you
|
|
|
|
write a commit log. You can use `git commit -m "Cool commit log"` to
|
2022-03-18 17:46:08 +01:00
|
|
|
write the log directly.
|
2023-01-12 19:43:03 +01:00
|
|
|
- `git commit --amend` lets you amend the last commit with your currently
|
|
|
|
staged changes (added with `git add`). This is the best option if you
|
2022-03-18 17:46:08 +01:00
|
|
|
want to fix a mistake in the last commit (bug, typo, style issue, etc.).
|
2023-01-12 19:43:03 +01:00
|
|
|
- `git log` will show you the last commits of your current branch. If you
|
2022-03-18 17:46:08 +01:00
|
|
|
did local commits, they should be shown at the top.
|
2023-01-12 19:43:03 +01:00
|
|
|
- `git show` will show you the changes of the last commit. You can also
|
2022-03-18 17:46:08 +01:00
|
|
|
specify a commit hash to see the changes for that commit.
|
|
|
|
|
|
|
|
That's a lot to memorize! Don't worry, just check this cheat sheet when you
|
|
|
|
need to make changes, and learn by doing.
|
|
|
|
|
|
|
|
Here's how the shell history could look like on our example:
|
|
|
|
|
2023-01-12 22:00:14 +01:00
|
|
|
```
|
2024-05-04 14:08:00 +02:00
|
|
|
# It's nice to know where you're starting from
|
|
|
|
$ git log
|
2022-03-18 17:46:08 +01:00
|
|
|
|
2024-05-04 14:08:00 +02:00
|
|
|
# Do changes to the project manager with the nano text editor
|
|
|
|
$ nano editor/project_manager.cpp
|
2022-03-18 17:46:08 +01:00
|
|
|
|
2024-05-04 14:08:00 +02:00
|
|
|
# Find an unrelated bug in Control and fix it
|
|
|
|
$ nano scene/gui/control.cpp
|
2022-03-18 17:46:08 +01:00
|
|
|
|
2024-05-04 14:08:00 +02:00
|
|
|
# Review changes
|
|
|
|
$ git status
|
|
|
|
$ git diff
|
2022-03-18 17:46:08 +01:00
|
|
|
|
2024-05-04 14:08:00 +02:00
|
|
|
# We'll do two commits for our unrelated changes,
|
|
|
|
# starting by the Control changes necessary for the PM enhancements
|
|
|
|
$ git add scene/gui/control.cpp
|
|
|
|
$ git commit -m "Fix handling of margins in Control"
|
2022-03-18 17:46:08 +01:00
|
|
|
|
2024-05-04 14:08:00 +02:00
|
|
|
# Check we did good
|
|
|
|
$ git log
|
|
|
|
$ git show
|
|
|
|
$ git status
|
2022-03-18 17:46:08 +01:00
|
|
|
|
2024-05-04 14:08:00 +02:00
|
|
|
# Make our second commit
|
|
|
|
$ git add editor/project_manager.cpp
|
|
|
|
$ git commit -m "Add a pretty banner to the project manager"
|
|
|
|
$ git log
|
2023-01-12 22:00:14 +01:00
|
|
|
```
|
2022-03-18 17:46:08 +01:00
|
|
|
|
2023-01-12 19:43:03 +01:00
|
|
|
With this, we should have two new commits in our `better-project-manager`
|
|
|
|
branch which were not in the `master` branch. They are still only local
|
2022-03-18 17:46:08 +01:00
|
|
|
though, the remote fork does not know about them, nor does the upstream repo.
|
|
|
|
|
2024-05-04 00:04:16 +02:00
|
|
|
## Pushing changes to a remote
|
2022-03-18 17:46:08 +01:00
|
|
|
|
2023-01-12 19:43:03 +01:00
|
|
|
That's where `git push` will come into play. In Git, a commit is always
|
2022-03-18 17:46:08 +01:00
|
|
|
done in the local repository (unlike Subversion where a commit will modify
|
|
|
|
the remote repository directly). You need to *push* the new commits to a
|
|
|
|
remote branch to share them with the world. The syntax for this is:
|
|
|
|
|
2023-01-12 22:00:14 +01:00
|
|
|
```
|
2024-05-04 14:08:00 +02:00
|
|
|
$ git push ( remote> ( local branch>[:( remote branch>]
|
2023-01-12 22:00:14 +01:00
|
|
|
```
|
2022-03-18 17:46:08 +01:00
|
|
|
|
|
|
|
The part about the remote branch can be omitted if you want it to have the
|
|
|
|
same name as the local branch, which is our case in this example, so we will
|
|
|
|
do:
|
|
|
|
|
2023-01-12 22:00:14 +01:00
|
|
|
```
|
2024-05-04 14:08:00 +02:00
|
|
|
$ git push origin better-project-manager
|
2023-01-12 22:00:14 +01:00
|
|
|
```
|
2022-03-18 17:46:08 +01:00
|
|
|
|
|
|
|
Git will ask you for your username and password, and the changes will be sent
|
|
|
|
to your remote. If you check the fork's page on GitHub, you should see a new
|
|
|
|
branch with your added commits.
|
|
|
|
|
2024-05-04 00:04:16 +02:00
|
|
|
## Issuing a pull request
|
2022-03-18 17:46:08 +01:00
|
|
|
|
|
|
|
When you load your fork's branch on GitHub, you should see a line saying
|
2024-03-16 20:56:52 +01:00
|
|
|
*"This branch is 2 commits ahead of pandemoniumengine:master."* (and potentially some
|
2023-01-12 19:43:03 +01:00
|
|
|
commits behind, if your `master` branch was out of sync with the upstream
|
|
|
|
`master` branch).
|
2022-03-18 17:46:08 +01:00
|
|
|
|
2023-01-12 20:16:00 +01:00
|
|
|
![](img/github_fork_make_pr.png)
|
2022-03-18 17:46:08 +01:00
|
|
|
|
|
|
|
On that line, there is a "Pull request" link. Clicking it will open a form
|
2024-03-16 20:56:52 +01:00
|
|
|
that will let you issue a pull request on the `pandemoniumengine/pandemonium` upstream
|
2022-03-18 17:46:08 +01:00
|
|
|
repository. It should show you your two commits, and state "Able to merge".
|
|
|
|
If not (e.g. it has way more commits, or says there are merge conflicts),
|
|
|
|
don't create the PR yet, something went wrong. Go to our
|
2024-03-16 20:56:52 +01:00
|
|
|
`Pandemonium Contributors Chat ( https://chat.pandemoniumengine.org/ )` and ask for support :)
|
2022-03-18 17:46:08 +01:00
|
|
|
|
|
|
|
Use an explicit title for the PR and put the necessary details in the comment
|
|
|
|
area. You can drag and drop screenshots, GIFs or zipped projects if relevant,
|
|
|
|
to showcase what your work implements. Click "Create a pull request", and
|
|
|
|
tadaa!
|
|
|
|
|
2024-05-04 00:04:16 +02:00
|
|
|
## Modifying a pull request
|
2022-03-18 17:46:08 +01:00
|
|
|
|
|
|
|
While it is reviewed by other contributors, you will often need to make
|
|
|
|
changes to your yet-unmerged PR, either because contributors requested them,
|
|
|
|
or because you found issues yourself while testing.
|
|
|
|
|
|
|
|
The good news is that you can modify a pull request simply by acting on the
|
|
|
|
branch you made the pull request from. You can e.g. make a new commit on that
|
|
|
|
branch, push it to your fork, and the PR will be updated automatically:
|
|
|
|
|
2023-01-12 22:00:14 +01:00
|
|
|
```
|
2024-05-04 14:08:00 +02:00
|
|
|
# Check out your branch again if you had changed in the meantime
|
|
|
|
$ git checkout better-project-manager
|
2022-03-18 17:46:08 +01:00
|
|
|
|
2024-05-04 14:08:00 +02:00
|
|
|
# Fix a mistake
|
|
|
|
$ nano editor/project_manager.cpp
|
|
|
|
$ git add editor/project_manager.cpp
|
|
|
|
$ git commit -m "Fix a typo in the banner's title"
|
|
|
|
$ git push origin better-project-manager
|
2023-01-12 22:00:14 +01:00
|
|
|
```
|
2022-03-18 17:46:08 +01:00
|
|
|
|
|
|
|
However, be aware that in our PR workflow, we favor commits that bring the
|
|
|
|
codebase from one functional state to another functional state, without having
|
|
|
|
intermediate commits fixing up bugs in your own code or style issues. Most of
|
|
|
|
the time, we will prefer a single commit in a given PR (unless there's a good
|
2022-09-10 12:15:58 +02:00
|
|
|
reason to keep the changes separate). Instead of authoring a new commit,
|
2023-01-12 19:43:03 +01:00
|
|
|
consider using `git commit --amend` to amend the previous commit with your
|
2022-03-18 17:46:08 +01:00
|
|
|
fixes. The above example would then become:
|
|
|
|
|
2023-01-12 22:00:14 +01:00
|
|
|
```
|
2024-05-04 14:08:00 +02:00
|
|
|
# Check out your branch again if you had changed in the meantime
|
|
|
|
$ git checkout better-project-manager
|
2022-03-18 17:46:08 +01:00
|
|
|
|
2024-05-04 14:08:00 +02:00
|
|
|
# Fix a mistake
|
|
|
|
$ nano editor/project_manager.cpp
|
|
|
|
$ git add editor/project_manager.cpp
|
|
|
|
# --amend will change the previous commit, so you will have the opportunity
|
|
|
|
# to edit its commit message if relevant.
|
|
|
|
$ git commit --amend
|
|
|
|
# As we modified the last commit, it no longer matches the one from your
|
|
|
|
# remote branch, so we need to force push to overwrite that branch.
|
|
|
|
$ git push --force origin better-project-manager
|
2023-01-12 22:00:14 +01:00
|
|
|
```
|
2022-03-18 17:46:08 +01:00
|
|
|
|
|
|
|
.. Kept for compatibility with the previous title, linked in many PRs.
|
|
|
|
|
|
|
|
.. _mastering-the-pr-workflow-the-rebase:
|
|
|
|
|
2023-01-12 20:49:14 +01:00
|
|
|
|
2022-03-18 17:46:08 +01:00
|
|
|
|
2024-05-04 00:04:16 +02:00
|
|
|
## The interactive rebase
|
2022-03-18 17:46:08 +01:00
|
|
|
|
|
|
|
If you didn't follow the above steps closely to *amend* changes into a commit
|
|
|
|
instead of creating fixup commits, or if you authored your changes without being
|
|
|
|
aware of our workflow and Git usage tips, reviewers might request of your to
|
|
|
|
*rebase* your branch to *squash* some or all of the commits into one.
|
|
|
|
|
|
|
|
Indeed, if some commits have been made following reviews to fix bugs, typos, etc.
|
|
|
|
in the original commit, they are not relevant to a future changelog reader who
|
2024-03-16 20:56:52 +01:00
|
|
|
would want to know what happened in the Pandemonium codebase, or when and how a given
|
2022-03-18 17:46:08 +01:00
|
|
|
file was last modified.
|
|
|
|
|
|
|
|
To squash those extraneous commits into the main one, we will have to *rewrite
|
|
|
|
history*. Right, we have that power. You may read that it's a bad practice, and
|
|
|
|
it's true when it comes to branches of the upstream repo. But in your fork, you
|
|
|
|
can do whatever you want, and everything is allowed to get neat PRs :)
|
|
|
|
|
2023-01-12 19:43:03 +01:00
|
|
|
We will use the *interactive rebase* `git rebase -i` to do this. This
|
2022-03-18 17:46:08 +01:00
|
|
|
command takes a commit ID or a branch name as argument, and will let you modify
|
|
|
|
all commits between that commit/branch and the last one in your working branch,
|
2023-01-12 19:43:03 +01:00
|
|
|
the so-called `HEAD`.
|
2022-03-18 17:46:08 +01:00
|
|
|
|
2023-01-12 19:43:03 +01:00
|
|
|
While you can give any commit ID to `git rebase -i` and review everything in
|
2022-03-18 17:46:08 +01:00
|
|
|
between, the most common and convenient workflow involves rebasing on the
|
2023-01-12 19:43:03 +01:00
|
|
|
upstream `master` branch, which you can do with:
|
2022-03-18 17:46:08 +01:00
|
|
|
|
2023-01-12 22:00:14 +01:00
|
|
|
```
|
2024-05-04 14:08:00 +02:00
|
|
|
$ git rebase -i upstream/master
|
2023-01-12 22:00:14 +01:00
|
|
|
```
|
2022-03-18 17:46:08 +01:00
|
|
|
|
2023-01-12 20:55:57 +01:00
|
|
|
Note:
|
|
|
|
Referencing branches in Git is a bit tricky due to the distinction
|
2023-01-12 19:43:03 +01:00
|
|
|
between remote and local branches. Here, `upstream/master` (with a
|
|
|
|
`/`) is a local branch which has been pulled from the `upstream`
|
|
|
|
remote's `master` branch.
|
2022-03-18 17:46:08 +01:00
|
|
|
|
|
|
|
Interactive rebases can only be done on local branches, so the `/`
|
|
|
|
is important here. As the upstream remote changes frequently, your
|
2023-01-12 19:43:03 +01:00
|
|
|
local `upstream/master` branch may become outdated, so you can
|
|
|
|
update it with `git fetch upstream master`. Contrarily to
|
|
|
|
`git pull --rebase upstream master` which would update your
|
|
|
|
currently checked out branch, `fetch` will only update the
|
|
|
|
`upstream/master` reference (which is distinct from your local
|
|
|
|
`master` branch... yes it's confusing, but you'll become familiar
|
2022-03-18 17:46:08 +01:00
|
|
|
with this little by little).
|
|
|
|
|
2023-01-12 19:43:03 +01:00
|
|
|
This will open a text editor (`vi` by default, see
|
2023-01-12 20:57:31 +01:00
|
|
|
`Git docs ( https://git-scm.com/book/en/v2/Customizing-Git-Git-Configuration#_core_editor )`
|
2022-03-18 17:46:08 +01:00
|
|
|
to configure your favorite one) with something which may look like this:
|
|
|
|
|
2023-01-12 22:00:14 +01:00
|
|
|
```
|
2024-05-04 14:08:00 +02:00
|
|
|
pick 1b4aad7 Add a pretty banner to the project manager
|
|
|
|
pick e07077e Fix a typo in the banner's title
|
2023-01-12 22:00:14 +01:00
|
|
|
```
|
2022-03-18 17:46:08 +01:00
|
|
|
|
|
|
|
The editor will also show instructions regarding how you can act on those
|
|
|
|
commits. In particular, it should tell you that "pick" means to use that
|
|
|
|
commit (do nothing), and that "squash" and "fixup" can be used to *meld* the
|
|
|
|
commit in its parent commit. The difference between "squash" and "fixup" is
|
|
|
|
that "fixup" will discard the commit log from the squashed commit. In our
|
|
|
|
example, we are not interested in keeping the log of the "Fix a typo" commit,
|
|
|
|
so we use:
|
|
|
|
|
2023-01-12 22:00:14 +01:00
|
|
|
```
|
2024-05-04 14:08:00 +02:00
|
|
|
pick 1b4aad7 Add a pretty banner to the project manager
|
|
|
|
fixup e07077e Fix a typo in the banner's title
|
2023-01-12 22:00:14 +01:00
|
|
|
```
|
2022-03-18 17:46:08 +01:00
|
|
|
|
|
|
|
Upon saving and quitting the editor, the rebase will occur. The second commit
|
2023-01-12 19:43:03 +01:00
|
|
|
will be melded into the first one, and `git log` and `git show` should
|
2022-03-18 17:46:08 +01:00
|
|
|
now confirm that you have only one commit with the changes from both previous
|
|
|
|
commits.
|
|
|
|
|
|
|
|
But! You rewrote the history, and now your local and remote branches have
|
|
|
|
diverged. Indeed, commit 1b4aad7 in the above example will have changed, and
|
|
|
|
therefore got a new commit hash. If you try to push to your remote branch, it
|
|
|
|
will raise an error:
|
|
|
|
|
2023-01-12 22:00:14 +01:00
|
|
|
```
|
2024-05-04 14:08:00 +02:00
|
|
|
$ git push origin better-project-manager
|
|
|
|
To https://github.com/akien-mga/pandemonium
|
|
|
|
! [rejected] better-project-manager -> better-project-manager (non-fast-forward)
|
|
|
|
error: failed to push some refs to 'https://akien-mga@github.com/akien-mga/pandemonium'
|
|
|
|
hint: Updates were rejected because the tip of your current branch is behind
|
|
|
|
hint: its remote counterpart.
|
2023-01-12 22:00:14 +01:00
|
|
|
```
|
2022-03-18 17:46:08 +01:00
|
|
|
|
|
|
|
This is a sane behavior, Git will not let you push changes that would
|
|
|
|
override remote content. But that's actually what we want to do here, so we
|
|
|
|
will have to *force* it:
|
|
|
|
|
2023-01-12 22:00:14 +01:00
|
|
|
```
|
2024-05-04 14:08:00 +02:00
|
|
|
$ git push --force origin better-project-manager
|
2023-01-12 22:00:14 +01:00
|
|
|
```
|
2022-03-18 17:46:08 +01:00
|
|
|
|
|
|
|
And tadaa! Git will happily *replace* your remote branch with what you had
|
2023-01-12 19:43:03 +01:00
|
|
|
locally (so make sure that's what you wanted, using `git log`). This will
|
2022-03-18 17:46:08 +01:00
|
|
|
also update the PR accordingly.
|
|
|
|
|
2024-05-04 00:04:16 +02:00
|
|
|
## Deleting a Git branch
|
2022-03-18 17:46:08 +01:00
|
|
|
|
|
|
|
After your pull request gets merged, there's one last thing you should do: delete your
|
|
|
|
Git branch for the PR. There won't be issues if you don't delete your branch, but it's
|
|
|
|
good practice to do so. You'll need to do this twice, once for the local branch and another
|
|
|
|
for the remote branch on GitHub.
|
|
|
|
|
|
|
|
To delete our better project manager branch locally, use this command:
|
|
|
|
|
2023-01-12 22:00:14 +01:00
|
|
|
```
|
2024-05-04 14:08:00 +02:00
|
|
|
$ git branch -d better-project-manager
|
2023-01-12 22:00:14 +01:00
|
|
|
```
|
2022-03-18 17:46:08 +01:00
|
|
|
|
|
|
|
Alternatively, if the branch hadn't been merged yet and we wanted to delete it anyway, instead
|
2023-01-12 19:43:03 +01:00
|
|
|
of `-d` you would use `-D`.
|
2022-03-18 17:46:08 +01:00
|
|
|
|
|
|
|
Next, to delete the remote branch on GitHub use this command:
|
|
|
|
|
2023-01-12 22:00:14 +01:00
|
|
|
```
|
2024-05-04 14:08:00 +02:00
|
|
|
$ git push origin -d better-project-manager
|
2023-01-12 22:00:14 +01:00
|
|
|
```
|
2022-03-18 17:46:08 +01:00
|
|
|
|
|
|
|
You can also delete the remote branch from the GitHub PR itself, a button should appear once
|
|
|
|
it has been merged or closed.
|