This gist describes example of simple workflow on repository whose changes are tracked by git and GitHub
# Go to directory where repository will be cloned (downloaded)
cd ~/Documents
# Clone repository from GitHub
git clone https://github.com/<user_or_organization_name>/<repository_name>
# Go into the clonned repository
cd <repository_name>
# First, check that your cloned repo is up-to-date with repo on GitHub
git pull
TIP - if git pull
ends with error: cannot pull with rebase: You have unstaged changes.
, you have probably already done some changes. You can store them temporarily using git stash
:
# store your local changes temporarily
git stash
# now, update your local repo
git pull
Now, you have an up-to-date repo and you can create you own local branch:
# Create (flag `-b`) and switch to a new branch where your changes will be stored
# NB - your_branch_name should contains your initials and descriptive branch name, e.g., jv/fix_typo_in_import
# If there is an open issue which you fix, include also the issue number, e.g., jv/001-fix_typo_in_import
git checkout -b <your_branch_name>
TIP - it is recommended to use single branch for single problem (issue), i.e., if you need to solve separate problems, solve them in two branched
Now you can apply the stored changes from the stash
:
git stash apply
# Check modified files
git status
# Add modified files into git
git add <file_1> <file_2> <file_XXX>
# Add descriptive massage which changes were done
# NB - commit messeage should be in present simple tense
git commit -m "Fix typo in library import"
TIP - individual changes in individual files can be shown using git diff
TIP - if git commit
fails on permissions, check this
# Push changes to GitHub (called origin)
git push -u origin <your_branch_name>
# NB - it is recommended to use same branch name (e.g., jv/fix_typo_in_import)
After making some changes and pushing of them to GitHub, go to repository on Github and open pull request (PR) and link the PR with issue, if it is opened (use Fixes
keyword)
The admin of the repository will review your PR and either merge it into the master or request changes
After merging of your branch to master by admin, update your local master branch
git checkout master
git pull
If some changes were done in master
branch on GitHub (e.g. by your colleague) while you are still working on your local branch, it is necessary to update (rebase) your local branch with GitHub master branch. (It is recommended to do this step periodically to avoid conflicts)
# Update your local master branch based on GitHub master
git checkout master
git pull
# Switch back to your local branch
git checkout <your_branch>
# Merge in changes (rebase is better than merge)
git rebase -i master
# This drop you into texteditor (vim in default)
# Type following to save it
:wq<enter>
# Then, you should see: "Successfully rebased and updated <your_branch>"
# Push your updated local branch to GitHub
git push -f