Git Workflow Guide


# 0a. Fork the repo.
git-workflow-guide 0a.i git-workflow-guide 0a.ii
# 0b. Clone the repo.

git-workflow-guide 0b

Joe:projects joeflack4$ git clone
Cloning into 'commcare-hq'...
remote: Counting objects: 846675, done.
remote: Compressing objects: 100% (149/149), done.
remote: Total 846675 (delta 104), reused 109 (delta 50), pack-reused 846472
Receiving objects: 100% (846675/846675), 415.87 MiB | 6.85 MiB/s, done.
Resolving deltas: 100% (627831/627831), done.
Checking out files: 100% (7490/7490), done.

# 0c. Make a virtual environment. I use virtualenvwrapper.

Joe:projects joeflack4$ mkvirtualenv commcare-hq
Running virtualenv with interpreter /usr/local/bin/python3
Using base prefix '/Library/Frameworks/Python.framework/Versions/3.6'
New python executable in /Users/joeflack4/virtualenvs/commcare-hq/bin/python3
Also creating executable in /Users/joeflack4/virtualenvs/commcare-hq/bin/python
Installing setuptools, pip, wheel...done.
virtualenvwrapper.user_scripts creating /Users/joeflack4/virtualenvs/commcare-hq/bin/predeactivate
virtualenvwrapper.user_scripts creating /Users/joeflack4/virtualenvs/commcare-hq/bin/postdeactivate
virtualenvwrapper.user_scripts creating /Users/joeflack4/virtualenvs/commcare-hq/bin/preactivate
virtualenvwrapper.user_scripts creating /Users/joeflack4/virtualenvs/commcare-hq/bin/postactivate
virtualenvwrapper.user_scripts creating /Users/joeflack4/virtualenvs/commcare-hq/bin/get_env_details

# 0d. Activate your virtual environment.
# Using virtualenvwrapper, this is done like so:

Joe:commcare-hq joeflack4$ workon commcare-hq
(commcare-hq) Joe:commcare-hq joeflack4$
# 0e. Change directory to the repo.
(commcare-hq) Joe:projects joeflack4$ pwd
(commcare-hq) Joe:projects joeflack4$ cd commcare-hq/
(commcare-hq) Joe:commcare-hq joeflack4$ pwd
(commcare-hq) Joe:commcare-hq joeflack4$ ls
CONTRIBUTING.rst app_builder_live_test docs locale
# ...and so on.

# 0f. Set up remote to trunk.

(commcare-hq) Joe:commcare-hq joeflack4$ git remote -v
origin (fetch)
origin (push)

git-workflow-guide 0f

(commcare-hq) Joe:commcare-hq joeflack4$ git remote add trunk
(commcare-hq) Joe:commcare-hq joeflack4$ git remote -v
origin (fetch)
origin (push)
trunk (fetch)
trunk (push)

# 1. You have a change you want to make.

# 2. You checkout a new branch based from the develop branch of the trunk repo.

(commcare-hq) Joe:commcare-hq joeflack4$ git branch
* develop
(commcare-hq) Joe:commcare-hq joeflack4$ git checkout -b my-new-feature-branch
Switched to a new branch 'my-new-feature-branch'
(commcare-hq) Joe:commcare-hq joeflack4$ git branch
* my-new-feature-branch

# 3. You work, adding commits to this “feature branch” (even if what you’re doing is not adding/updating a specific feature).
# I made some changes to the .gitignore.

(commcare-hq) Joe:commcare-hq joeflack4$ git status
On branch my-new-feature-branch
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)

modified: .gitignore

no changes added to commit (use "git add" and/or "git commit -a")
(commcare-hq) Joe:commcare-hq joeflack4$ git add .
(commcare-hq) Joe:commcare-hq joeflack4$ git commit -m "Updated gitignore."
[my-new-feature-branch d0b7774] Updated gitignore.
1 file changed, 1 insertion(+)

# Might as well push changes to Github while I”m at it.

(commcare-hq) Joe:commcare-hq joeflack4$ git push
fatal: The current branch my-new-feature-branch has no upstream branch.
To push the current branch and set the remote as upstream, use

git push --set-upstream origin my-new-feature-branch

# Woops! Forgot to set an upstream branch on Github.

(commcare-hq) Joe:commcare-hq joeflack4$ git push --set-upstream origin my-new-feature-branch
Counting objects: 3, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 291 bytes | 0 bytes/s, done.
Total 3 (delta 2), reused 0 (delta 0)
remote: Resolving deltas: 100% (2/2), completed with 2 local objects.
* [new branch] my-new-feature-branch -> my-new-feature-branch
Branch my-new-feature-branch set up to track remote branch my-new-feature-branch from origin.

# 4. When ready, make a pull request to the develop branch of the trunk repo.

(commcare-hq) Joe:commcare-hq joeflack4$ git home

# Doing ‘git home’ opens git in the browser.

git-workflow-guide 4a

git-workflow-guide 4b

# 5. The pull request is reviewed, some code review / change requests may be provided, and ultimately once the review is passed, the merge is accepted into develop.

# 6. If no testing is needed, skip to step 9. If testing is needed, continue with this step: When ready to deploy changes for testing, the staging branch merges changes from the develop branch.

# 7. Staging branch is pushed to staging instance.

# 8. Testing is done on the staging instance.

# 9. When testing on staging is complete, develop is merged into the master or production branch.

# 10. Master or production branch is pushed to the production instance.

# 11. Testing is done on the production instance.

# 12. When testing on production is complete, the workflow is finished. Your change has been implemented!

Leave a Reply

Your email address will not be published. Required fields are marked *


This site uses Akismet to reduce spam. Learn how your comment data is processed.