wiki:HowToGit

Version 39 (modified by martinl, 5 years ago) ( diff )

cosmetics

Contributing guidelines

The development workflow changes notably after migration from Subversion to Git (GitHub).

The repo is here: https://github.com/OSGeo/grass

Important changes:

  • direct committing to "master" (former "trunk") is a no-go and disabled
  • hence: you will create a feature branch and open a pull request for a change
    • Rationale: pull requests are the perfect platform to discuss/improve changes before merging.
    • also applies to core developers (to be discussed)

Workflow

  • fork the GRASS GIS repository, and create feature branch(es) with the changes, and suggest your changes as pull requests.

First fork the GRASS GIS repo in the GitHub UI to your_GH_account.

Workflow for core developers

- to be discussed which way -

Add: https://help.github.com/en/articles/connecting-to-github-with-ssh

One time only:

# "origin" points to your fork repo - IMPORTANT
git clone git@github.com:your_GH_account/grass.git

# add "upstream" remote
cd grass/
git remote add upstream git@github.com:OSGeo/grass.git

git remote -v
# you should see something like
origin	  git@github.com:your_GH_account/grass.git (fetch)
origin	  git@github.com:your_GH_account/grass.git (push)
upstream  git@github.com:OSGeo/grass.git (fetch)
upstream  git@github.com:OSGeo/grass.git (push)

Working with git:

# <make local source code changes>
vim ...

# fetch all branches from all remotes
git fetch --all

# list existing branches
git branch -a

# create new local branch (pick a new name for feature_branch_name)
git checkout -b feature_branch_name

# list local changes
git status
git add file1.c file2.py ...
git commit -m 'my change with reasonable explanation...'

# push feature branch to origin, i.e. your fork of the OSGeo/grass repo
git push origin feature_branch_name
# create pull request in GitHub Web interface (the link is then shown in the terminal)

# during PR review phase, make more local changes if needed
git add .
git commit -m 'my second change'
git push origin feature_branch_name
# ..... will be added to existing pull request

NOTE: for different pull requests, simply create different feature branches.

Workflow for external contributors

  • to be discussed: is this needed at all? Maybe above part is enough -

First fork the GRASS GIS repo in the GitHub web interface.

You clone the GRASS GIS repo and add the fork as an additional remote (or the other way around), this makes merging changes from the GRASS GIS repo easier.

# create fork via GitHub Web interface

# checkout your the osgeo repo
git clone https://github.com/OSGeo/grass.git

# go to repo dir
cd grass

# add your fork as another remote
git remote add fork https://github.com/<your_GH_account>/grass.git

# change the push URL for your fork to SSH if you have it set up
git remote set-url --push fork ssh://git@github.com/<your_GH_account>/grass.git

# all steps see above, core dev section (branch, edit, commit)
...

# push feature branch to your own fork repo of GRASS GIS

git push fork <feature-branch>

# create pull request in GitHub Web interface (the link is shown conveniently in the terminal)

This way origin is the authoritative source for the code, and additional remotes are forks.

What is missing above is how you actually update the repo with changes in OSGeo repo master branch.

Alternative is to clone your fork and add osgeo as another remote ("option 2" - "clone fork" as opposed to "clone osgeo"). This would be the same as what GitHub documentation suggests. See: Fork a repo and Syncing a fork in GitHub help.

Keep your local source code up to date

[from https://github.com/OSGeo/gdal/blob/master/CONTRIBUTING.md#working-with-a-feature-branch]

You may need to resynchronize against master if you need some bugfix or new capability that has been added since you created your branch

# assuming that "upstream" points to OSGeo/grass
git fetch upstream
git rebase upstream/master

# if rebase fails with "error: cannot rebase: You have unstaged changes...", then move your uncommitted local changes to "stash"
git stash
# now you can rebase
git rebase upstream/master
# apply your local changes on top
git stash apply && git stash pop

Continue do your changes and commit/push them (ideally to a feature branch, see above).

Review of pull requests

In the review phase, PRs can be commented and modified.

TODO add more

Merging of pull requests

The CI should run successfully for every commit (chunk of commits in PR to be exact) before it goes into the respective branch.

How to accept PR:

-- to be discussed --

  • Merge pull request

OR

  • Squash and merge

... based on PR nature.

Switching between branches

For an elegant way of multi-branches in separate directories with only a single repo clone, see

https://lists.osgeo.org/pipermail/grass-dev/2019-May/092653.html

Backporting to release branches

TODO

See also https://github.com/OSGeo/gdal/blob/master/CONTRIBUTING.md#backporting-bugfixes-from-master-to-a-stable-branch

Further reading

Note: See TracWiki for help on using the wiki.