Skip to content

Instantly share code, notes, and snippets.

@valosekj
Last active November 7, 2022 14:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save valosekj/2557c25ff096ff3628e1bbdbff8cc1cc to your computer and use it in GitHub Desktop.
Save valosekj/2557c25ff096ff3628e1bbdbff8cc1cc to your computer and use it in GitHub Desktop.
Simple workflow of collaboration in small team using git and GitHub

Simple workflow of collaboration in small team using git and GitHub

This gist describes example of simple workflow on repository whose changes are tracked by git and GitHub

1) Clone (download repository from GitHub to your computer)

# 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>

2) Propose some changes

2a) Create a new branch where your changes will be stored

# 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

2b) After doing of some changes, commit these changes into your local branch

# 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

2c) Push (upload) your modified files on GitHub

# 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)    

3) Open pull request

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

4) Update your local repository

After merging of your branch to master by admin, update your local master branch

git checkout master
git pull

5) Update your local branch with GitHub master branch

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment