Skip to content

Team Working in Git

IanMayo edited this page Nov 10, 2014 · 15 revisions

Requirements

Here's a glossy description of how we use Git & GitHub: https://guides.github.com/introduction/flow/index.html

In order to contribute to Debrief you should follow next steps:

1. Forking main Debrief repository

  1. enter https://github.com/debrief/debrief in your browser
  2. sign-in to github
  3. click the Fork button
  4. you can accept defaults in the "Fork debrief/debrief" page and click the "Fork Repository" button

You will get your copy of the main Debrief repository with SSH URL as: git@github.com:pecko/debrief.git Replace "pecko" with your github username that you will see in your Debrief page (git@github.com:<YOUR_USERNAME>/debrief.git)

2. Clone your repository

cd ~ // you can use some directory

git clone git@github.com:<YOUR_USERNAME>/debrief.git

cd debrief

Notice: it is your repository containing your username in the URL.

3. Create link to remote repository (main Debrief repository)

This step is obliged in order to sync your repository with main debrief repository

git remote add upstream git@github.com:debrief/debrief.git

The upstream reference is usual, but you can select some other valid reference.

Notice: You enter the URL of main repository here containing debrief, but not your username.

4. Fetch upstream repository

From your local repository enter:

git fetch upstream

git push origin

The push updates your forked repository. Steps 1-4 are done only once (beside you move to other local machine)

5. Contributing

If you want add a new Debrief feature or fix a ticket, you would start with creating a new branch:

git checkout -b myfeature

You can use this command even you forget it and makes some change in your master branch (if you don't commit it).

5.2 Coding ...

Make your code changes.

5.3 Committing

Enter the following in your myfeature branch

git commit -a -m "My Feature"

5.4 Rebasing/syncing

The main tree can be changed during your coding. You have to rebase.

git checkout master

git pull --rebase upstream master // your remote reference is upstream

git fetch upstream // update tags from main repo

git push origin

git checkout myfeature

git rebase master

If there is a conflict you have to fix it.

5.5 Push your branch

git push origin myfeature

6. Creating the PR

go to on your github Debrief page and select Pull Request
select your branch and main repository branch (usually debrief/debrief)
click Create Pull Request

7. Update pull request

7.1 commit all new changes

git commit -a -m "A new request"

or add in existing commit

git commit -a --amend

7.2 push branch

git push origin

or

git push origin -f // if you change existing commit

7.3 repeat the procedure 6.

The PR will be updated automatically on github.

8. Sync with main repository

You should enter these commands periodically:

git checkout master

git pull --rebase upstream master // your remote reference is upstream

git fetch upstream // update tags from main repo

git push origin

Now you can rebase your outstanding branches and update the PRs.

When your PR has been merged, you can safely remove corresponding branch in local and remote repository.

git branch -d <branch_name> //remove local branch (or git branch -D <branch_name>)

git push origin :<branch_name> // remove remote branch

9. Working with pull request

9.1 Reviewing pull request

The "SomeUser" user creates branch hotfix against master in its fork 'https://github.com/SomeUser/debrief.git' and create pull request. We can review it in the following way:

git checkout -b review-hotfix master // review-hotfix can be some name

git pull https://github.com/SomeUser/debrief.git hotfix

Reviewing the PR ...

9.2 Merging pull request

If the PR created in step 9.2 is fine, you can merge the PR.

git checkout master

git merge review-hotfix

or git merge --no-ff review-hotfix, but it will create one additional commit (merge branch XXX)

git push origin master