Skip to content

Instantly share code, notes, and snippets.

@sivel
Last active October 16, 2023 16:44
Show Gist options
  • Save sivel/e5ba4d589102b8d44a05 to your computer and use it in GitHub Desktop.
Save sivel/e5ba4d589102b8d44a05 to your computer and use it in GitHub Desktop.
Ansible Contributors Guide for working with git/GitHub

Ansible Contributors Guide for working with git/GitHub

First Note

Never, ever, modify or commit things to devel, always do work in a feature branch

Setting up the ansible and modules repos from forks

export GITHUB_USER=sivel
git clone git@github.com:$GITHUB_USER/ansible.git
cd ansible
git remote add upstream https://github.com/ansible/ansible.git
git fetch --all
git submodule update --init --recursive
git submodule foreach 'git remote add upstream $(git config --get remote.origin.url)'
git submodule foreach 'git remote set-url origin git@github.com:$GITHUB_USER/ansible-modules-$(basename $name)'
git submodule foreach 'git fetch --all'
git submodule foreach 'git checkout origin/devel && git merge upstream/devel && git push origin devel'
git submodule update

Testing a pull request

git fetch upstream pull/1234/head:pr/1234
git checkout pr/1234
# DO TESTING
cd $(git rev-parse --git-dir | awk -F'.git' '{print $1"."}')
git checkout devel
git submodule update

The above will work for a submodule as well, just cd to lib/ansible/modules/core first, all other commands are the same

Working on code for PR submission

git checkout devel
git fetch upstream
git merge upstream/devel
git checkout -b issue/12345 # If there is no existing issue, use a descriptive name instead
# DO WORK HERE
git add -p # Only add changes you want
git commit -m "This is a description. Fixes #12345"
git push
git checkout devel
cd $(git rev-parse --git-dir | awk -F'.git' '{print $1"."}')
git submodule update

Rebasing branch off of upstream/devel

git checkout your-feature-branch
git fetch upstream
git rebase -i upstream/devel
git push -f # Because you rebased and rewrote history you have to force push
git checkout devel
cd $(git rev-parse --git-dir | awk -F'.git' '{print $1"."}')
git submodule update

In the git rebase -i step, you can squash, reword and omit commits as needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment