Anything in master branch is always deployable

Read the github post <Understanding the github flow> before start this tutorial.

Making changes on a repository consists following steps

  • Stage
  • Commit
  • Push

Create a repository

You can either create a brand-new repository directory from scratch or use some template for better project management.

Example templates:

Collaboration with group member

Invite the collaborator

navigate to the setting under the repository webpage, add the collaborator as shown in the figure.

drawing

Collaborator contribute

If you are vscode user, there is git GUI for workflow management.

When the collaborate contribute, they normally create a new branch.

  1. Keep the master branch up-to-date.
    $ cd </path-to-the-repository>
    $ git pull
    
  2. Create a new branch from the master branch, and work on it
    $ git checkout -b <name-of-new-branch>
    

    which is equivalent as

    $ git branch <name-of-new-branch>
    $ git checkout <name-of-new-branch>
    
  3. working on the new feature locally, and dont forget to push it to the remote server (allow others see your code).
    $ git push origin <name-of-new-branch>
    
  4. Merge the created branch to master branch, then delete the branch.
    $ git checkout master # change to the master branch
    $ git merge <name-of-new-branch>
    $ git commit
    $ git push
    $ git branch -d <name-of-new-branch>
    

Branch types

branch graph

Recommand to use git-flow for branch organization. Use this tutorial for gitflow.

  • master branch:perform tagging and release on this branch.
  • develop branch: checkout from master branch. This branch normally won’t be modified directly, instead it checkout new feature branches, then merge them back on this develop branch.
  • release branch: checkout from develop branch. This branch is used for the test before version release, with minor bug fix. If bug fix is complicated, merge back to the develop branch then may working from other branches. After this branch is well-tested, merge it back to both develop and master branch.
  • feature branch: checkout from develop branch. Every team-member host independent feature branches for feature development. When the development is done, merge it back to develop branch.
  • fix branch: checkout from develop branch for bug fix. After the bug is fixed, merge it back to the develop branch, then delete this fix branch.
  • hotfix branch: checkout from master branch for bug fix. After the bug is fixed, merge back to both master and develop branch, then delete this hotfix branch.

Exmaple commands in git-flow

$ git flow init # initialization with git-flow
$ git flow feature start <feature_branch>
$ git flow feature finish <feature_branch>
$ git flow release start <0.1.0>
$ git flow release finish '0.1.0'

Other commands to be used

Commands for branch management:

$ git branch # show local branches
$ git branch -a # show local and remote branches
$ git branch -d <name-of-new-branch> # delete the local branch
$ git branch -D <name-of-new-branch> # force delete the local branch
$ git push <remote_name> --delete <branch_name> # delete remote branch$ git push <remote_name> :<branch_name>
$ git push <remote_name> :<branch_name> # delete remote branch

The remote name can be shown by:

$ git remote # the remote is <origin> in github

Include a third-party repository in the current repo

We follow the commands described in this post using git submodule:

git submodule add https://github.com/ufoym/imbalanced-dataset-sampler

Moreover, a very important setting of the 3rd-party repo (fork the repo but can sync with the original repo) is discussed in the this post.

Other useful tutorials

Basically, I rank the tutorial based on the value I found in it: