Git workflow
============

Proposing a pull request
------------------------

Patches are welcome to our library repository: https://github.com/openturns/openturns.

Here are the steps required to propose a modification with git:

1. Setup git for first time use::

    git config --global user.name "John Doe"
    git config --global user.email "johndoe@example.com"
    git config --global branch.autosetuprebase remote


2. Register on `GitHub <https://github.com>`_ and add a new ssh key in https://github.com/settings/ssh::

    ssh-keygen -t ed25519 -C "johndoe@example.com"
    cat ~/.ssh/id_ed25519.pub


3. Fork the library repository https://github.com/openturns/openturns and clone it via ssh::

    git clone git@github.com:doe/openturns.git doe
    cd doe


4. Create a branch from master with a relevant topic name::

    git checkout -b branch_name master


5. Commit your changes, split your work in several commits if needed to ease reviewing.
   You want to avoid including several unrelated tasks into a single commit.::

    git add <files> # Add current state of files to commit
    git commit
    ...
    git add <files>
    git commit

To write a nice commit message, keep a short commit title (less than 50 characters),
leave a blank line, then add a more detailed description.
It can be useful to prefix the title with the class or area in the library
concerned by the commit.
If the commit fixes an issue, add `Closes #NNN` to the message body that
way it will be closed automatically on merge.
For example::

    QuadraticLeastSquares: Fix quadratic term

    Closes #2412

Also update the ChangeLog file accordingly.

6. Push the new branch to your personal repository::

    git push --set-upstream origin branch_name


7. Create a pull request on https://github.com/openturns/openturns

That's it, your code is ready for reviewing, but it may not be accepted as is.

Checkout the comments made after your pull request and the automated test result.

You may want to push more commits to that branch as required.

Propose a separate pull request for each topic you want to address.

Here are more resources on `using pull requests <https://help.github.com/articles/using-pull-requests/>`_
and `Git <https://git-scm.com/book/en/v2>`_.


Keep your local repository in sync
----------------------------------

You may want to keep your personal repository in sync with the main repository
before starting new developments.

1. Add upstream remote repository::

    git remote add upstream https://github.com/openturns/openturns.git


2. Retrieve usptream::

    git fetch upstream


3. Create a new branch from the main repository master branch::

    git checkout -b new_branch_name upstream/master


You may also want to synchronize your current topic branch with the main repository:

1. Add upstream remote repository::

    git remote add upstream https://github.com/openturns/openturns.git


2. Retrieve usptream::

    git fetch upstream


3. Rebase your current branch to the main repository master branch::

    git rebase upstream/master


Delete a branch
---------------

Once your pull-request is merged, you may want to delete the branch.

1. Delete local branch::

    git branch -d branch_name


2. Delete remote branch::

    git push origin :branch_name


Tagging a release
-----------------

0. List existing tags::

    git tag


1. Get the master branch::

    git checkout master


2. Create the tag on local repository::

    git tag -a v2.0 -m 'version 2.0'


3. Push the tag on the remote repository::

    git push origin v2.0
