Skip to content

holytiny/github-git-workflow

Repository files navigation

Git Work Flow for Github

Motivation

Sometimes we will find that we need to execute lots of git command to make a pull request. For example, if we need to make a pull request to merge feature/fa branch, we need to do:

# remove deleted origin branches git fetch -p origin # update main branch to avoid potential conflicts git switch main git pull --rebase origin main # update the current feature branch to avoid potential conflicts git switch feature/fa git rebase main # create pr gh pr create -f --base main # show current branch git branch

These steps are tedious. It's better that we can wrap these steps to one single command, and that is exactly what github-git-workflow does!

Install

github-git-workflow uses script-launcher and github command cli gh, so you need to install gh firstly and then script-launcher.

Firstly, install gh, and make sure you have logged in.

Secondly, install script-launcher.

npm install script-launcher -D

Then add start: launch to the package.json scripts section:

{..."scripts":{"start": "launch", ... }, ... }

Then copy launcher-config.json to your project dir, in the same dir as your package.json file.

Usage

Github-git-workflow uses git topic branch, feature/_ branches for adding new features and hotfix/_ branches for fixing issues directly from main branch.

The life cyle of branches are create, finish and delete.

create: create the topic branch

finish: create the pull request from the topic branch, use this command to avoid potential conflicts

verify: if something wrong for pull request, after serveral commits you may fix the issue, then use verify to push local fix to remote topic branch to avoid potential conflicts

version: version command is used in main branch, after the pull request is approved, version command can be used to add version tag to the main branch.

delete: after pull request is merged to main branch, delete the local topic branch

Feature Branch

Feature branch is operated using rebase as much as possible to solve potential conflicts in local topic branch before the pull request.

Create

feature:name

Create a feature topic branch named doc

npm start feature:doc

Then a new branch named feature/doc should be created.

* feature/doc main

Finish

finish-feature:name # or for short ff:name

After all development and test, we can use finish command to creat the pull request.

npm start finish-feature:doc # or for short npm start ff:doc

The command should create a pull request.

Verify

verify-feature:name # or for short vf:name

If there's someting wrong with the pull request, and we fix the problem in local branch after several commits, then we can use verify command to push these commits to the remote branch of this pull request.

npm start verify-feature:doc # or for short npm start vf:doc

Delete

delete-feature:name # or for short df:name

After the pull request is approved, we can use delete-feature command to delete the topic branch.

npm start delete-feature:doc # or for short npm start df:doc

Hotfix Branch

Hotfix branch is used to fix issues in released version. It doesn't use rebase, conflicts are solved in pull request.

Create

hotfix:name:version

This command create a branch named hotfix/name from the specific version tag, the version is a git version tag.

npm start hotfix:doc:v1.0.1

After the command, a branch named hotfix/doc is created.

* hotfix/doc main

Finish

finish-hotfix:name # or fh for short fh:name

This command create a pull request from the topic branch.

npm start fh:doc

Verify

verify-hotfix:name # or vf for short vf:name

The same as verify-feature, however, it doesn't rebase the topic branch from main branch.

npm start vf:doc

Delete

delete-hotfix:name # or dh for short dh:name

The same as delete-feature, to delete the hotfix branch after the pull request is approved.

npm start dh:doc

Version

Version command uses npm version to add tag go main branch.

If the version before executing the command is v1.0.0

npm start prepatch # v1.0.1-0
npm start patch # v1.0.1
npm start preminor # v1.1.1-0
npm start minor # v1.1.1
npm start premajor # v2.1.1-0# The recommand way is to use alpha or beta command rather than premajor
npm start major # v2.1.1
npm start alpha # v2.1.1-alpha.0
npm start beta # v2.1.1-beta.0
# or specify the preid npm start prerelease:omega # v2.1.1-omega.0
# or specify the version# npm start version:semver npm start version:2.2.0 # v2.2.0

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published