element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Community Hub
Community Hub
Member Blogs Firmware Version Control with GitHub part 1: Branch Strategy for New Features
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Leaderboard
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Community Hub to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: Jan Cumps
  • Date Created: 8 May 2020 10:09 AM Date Created
  • Views 4524 views
  • Likes 11 likes
  • Comments 21 comments
  • tutorial
  • github
  • version_control
  • learning
  • git
  • gitlab
  • github_repository
Related
Recommended

Firmware Version Control with GitHub part 1: Branch Strategy for New Features

Jan Cumps
Jan Cumps
8 May 2020

image

 

A possible strategy for using GIT and working with branches.

In this part 1: working on new developments.

In part 2: bug fixes on the released code

image

I am suggesting a GitHub process, but it translates to other platforms with pull request support, E.g.: Azure DevOps, GitLab, Bitbucket, ...

The examples are using the repository of the eLoad.

I am using a single repository but it works virtually the same if contributors work from their own forked repository.

 

 

Branch Strategy Principles

 

Single Branch

You can work with a single branch. Git always comes with a default master branch.

If all you want to do is have a version controlled repository, you can give commit access to all contributors and that's that.

No need to read any further. You're good image.

 

image

In the images, the vertical lines represent Git branches. The horizontal arrows are actions.

 

Feature Branches

If you want to control what goes into the master (or any meaningful) branch, you can use the feature branch strategy.

In that case, you allow contributors to create their own branches on the fly*2. You don't give them commit access to the master branch.

Feature branches are short-lived by design. They are meant to work on one aspect of the software.

The developer works in that branch and has all the advantages of version control. Changes are tracked, but they stay safely in that feature branch.

It doesn't matter if non-working or partial code is checked in. The "official" code base is not impacted.

 

Once development is deemed finished - you can set rules here if wanted, like all test cases passed, code style checks passed, .... - the developer can create a pull request.

This is where the hosting site matters*1. They support this process to generate the request and get it merged into the official branch.

Once the repository admins accept that pull request, the feature branch is typically deleted because it has lived its life. No need to keep that.

The change will be eternally traceable via the pull request that stays in the repository forever.

 

Branch Policy

The hosting platforms all have some way to set the rules for branches.

You can set who can commit / merge, what type of merges are allowed, who's approval is needed, or no rules at all (typical for feature branches).

If you want your master branch managed, then restrict commit, and set at least one approver.

A pull request creator should not be able to accept their own changes.

This will take care that no one can directly write into the managed branch, and everything can be reviewed and accepted before merging features.

 

image

If you have an unpopular open source project and you're the only contributor, you can still use this approach, but enable "admin override".

In that case you can accept your own pull requests. Not an issue because it's your repository. You're the boss. You do as you please.

 

Project / Development Branch

When you want a stable master branch that represents the official released code, and you have active development going on, then there's the possibility to create long living additional managed branches.

The development branch starts as a clone from the master.

You'd want to set up a policy for such a branch too, similar as the master branch.

Then developers will create feature branches based on that development branch, not the master.

Their process is the same as explained in the Feature Branch section, while they are developing inside that feature branch.

But once done, they create a pull request to the development branch. Not to the master branch.

When the admin approves the request, code is merged into the development / project branch and the feature branch is deleted. Job done.

The repository admin should not accept direct pushes from such a feature branch into master.

 

At release time, the release manager (or you if you are lonely) will create a pull request with the development / project branch changes to the master branch.

Once the repository admin accepts that request, this is the new released version.

 

image

 

You can have several managed development / project branches in a complex project.

Just keep in min that everyone needs to understand what branch is for what, who manages it and where the results should flow to.

My advise is to start simple. And if that simple approach works, don't make it more complex.

Only if you can't manage the contributions in a simple way, then add. See my last line in the Single Branch section for a similar advice.

 

 

In the next part I'll add an approach to allow bug fixes in the master branch. Managed, and with a solution to integrate them in the development branch.

Comments and critiques are very welcome. There are better approaches than mine.

 

 

 

 

*1: or doesn't matter - if you use Git's own mechanism to create patches and mail notifications to request merge.

That approach is not the subject of this post. I want to document the process with pull management.

 

*2: in open source projects, it's common to have everyone run their own fork, instead of allowing the contributors to create branches in your account.

Everything works similar as here. They can create pull requests from such a forked repository into (one of our) branches.

Advantages:

  • you don't have to create and manage users. And several of the suggested repository hosts have a limit on their free tier.
  • The contributor can have their own strategy and approach. You aren't impacted by how they manage the code.
    The only thing you see is a pull request, just like one from a local feature branch.

Some of the hosts have project / issue management to assist the discussion with the contributors.

 

Related Blog
Firmware Version Control with GitHub part 1: Branch Strategy for New Features
Firmware Version Control with GitHub part 2: Branch Strategy for Bug Fixes
Firmware Release with GitHub: Branch, Issue, Pull Request and Project support
Fix a Bug in Production with GitHub: Issue, Branch, Project and (Draft) Pull Request supported + Eclipse Git Plug-in
Break-Fix with GitHub: part two: push bug fixes to the development team
GitHub and GIT: sign your commits with a certificate
GIT course
  • Sign in to reply

Top Comments

  • colporteur
    colporteur over 5 years ago in reply to Jan Cumps +3
    Jan Cumps I'm willing to take your scratch pad notes and drawing and convert them to vector drawings (Inkscape) if you are interested? I have a few cycles now that my RoadTest review The Road to Raspberry…
  • Jan Cumps
    Jan Cumps over 5 years ago in reply to colporteur +3
    yes, everything I post on the community is open - feel free to copy or alter. If you're looking for a cleaner drawing, the link I posted in the previous comment has a different and more organised drawing…
  • colporteur
    colporteur over 5 years ago in reply to Jan Cumps +2
    It was a philanthropic offer to lighten a perceived burden. I was thinking that this was part of a larger project for publication within the E14 Community. If you had a need I am willing to create the…
  • Jan Cumps
    Jan Cumps over 5 years ago in reply to Workshopshed +2
    Yes, you can plug in automated build. Automated test scenario run. Automated review against coding standards. All of these are wins. And the effort to achieve those lowers significantly if you actually…
  • Jan Cumps
    Jan Cumps over 5 years ago in reply to Workshopshed +2
    My claim to fame is an mid-2000 unit test project for ERP developers - with CVS at the time, but the process was agile - not at all tied to a version control system Downloaded 20.000 times. Used in commercial…
  • Jan Cumps
    Jan Cumps over 5 years ago +1
    For a full-fledged approach: https://nvie.com/posts/a-successful-git-branching-model/
  • Jan Cumps
    Jan Cumps over 5 years ago +1
    What I haven't discussed here is that GitHub also has "SCRUM board" style project support: The task here is attached both to an "issue" that supports this work .... ... and the related pull request(s)…
  • Workshopshed
    Workshopshed over 5 years ago +1
    Interesting to see embedded development using these techniques. I saw a talk from Arm the other week about CI and automated testing which is something you can do once you start using tools like git.
  • yuricts
    yuricts over 5 years ago in reply to colporteur +1
    Personally I prefer using the console commands for git... I do acknowledge that sometimes it is nice to see graphical interfaces with branches and all, but using the command line just gives me a better…
  • shabaz
    shabaz over 5 years ago in reply to colporteur +1
    Hi Sean, I use Visual Code with Git, however I'm conscious that if I move to a different IDE/editor then I'd need to learn the commands! So it's good to know the command-line syntax, but I don't know it…
  • Jan Cumps
    Jan Cumps over 4 years ago in reply to Workshopshed

    If two of your colleagues both decide to do a big rewrite at the same time then you can have a nightmare merging them back together. For that case a strategy of restricting to one person doing radical changes or pair programming can work.

    Yes. No version control system can solve if people working on the same code base don't talk.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Workshopshed
    Workshopshed over 4 years ago

    Having spent just over 2 months now using git flow (the branching model, not the software) pretty much daily at work. I can conclude that it mostly works. We commit and merge code daily and release multiple times per week to production. Not as fast as some places but it seems to be mostly working.

     

    Git flow works really well when the changes made in the different features don't affect the same parts of the code. One strategy for dealing with releasing several overlapping features at the same time is the release branch approach.

    It works really well when you submit the features to dev and then to master quite frequently.

     

    Things that will cause you grief:

    If two of your colleagues both decide to do a big rewrite at the same time then you can have a nightmare merging them back together. For that case a strategy of restricting to one person doing radical changes or pair programming can work.

    It does not work so well when you've got automated tools generating files that are source controlled. If possible, don't include those files if possible let them get regenerated by your build pipeline.

     

    If you've got a few people in your team and are working on multiple features, I can also recommend a branching visualiser tool, we use gitkraken but there are plenty of others about.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Andrew J
    Andrew J over 4 years ago

    Following on to wrap up (I started on the false assumption you were describing the use of gitflow without actually mentioning it!) 

     

    gitflow follows the same branching strategy as you describe here which isn't surprising as it originates from the same place.  By default, it isn't geared up to use Pull Requests as you do, and I think that could be a concern for many development cooperations.  Not so much for hobbyists who could keep things simple of course!

     

    Instead of Pull Requests, gitflow uses a concept of 'Finish', e.g. (once the release changes are committed):

     

    git flow finish release/Release1.0.1

     

    This just wraps a number of git commands into one operation: e.g. for a release branch, merges it into 'master' and 'development' and deletes the branch.  All on local.  A push to remote is required to then sync these two branches.  All cooperating developers follow the same process and Pull Requests aren't involved.

     

    It took a bit of searching to work out how to integrate gitflow and Pull Requests and it is possible.  Instead of running the git finish command: commit and push the changes when done, then raise the Pull Request as you describe and follow it through.  Finally, delete the branch on local manually - gitflow doesn't actually care if 'finish' is run or not.  It's even possible to integrate the Pull Request / finish approaches, and desirable if one is settled on using gitflow, better described by this chap in his video - the actual description of this specific approach is close to the end:

     

    You don't have permission to edit metadata of this video.
    Edit media
    x
    image
    Upload Preview
    image

     

    What's described is a way of doing what you suggest as an approach but automating a lot of it with 'standardised' functions.  If that makes sense: standardised in the sense that people seem to have settled on the gitflow implementation that can be downloaded. 

     

    This has been an interesting few posts to follow and understand Jan, thanks for creating them.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Andrew J
    Andrew J over 4 years ago in reply to Jan Cumps

    I have played around with the command line in the past so I have a reasonable basic understanding.  gitflow is the 'product' gitflow - I assume that under the covers GitKraken is running commands such as "git flow release..."  From what I could tell, it automates the process you describe but it doesn't seem to use Pull Requests as the one major difference.  Certainly its branching strategy appears to be the same.

     

    Development hasn't pushed up to remote so that's something to check out in the morning; I'd assumed that 'pushing' to remote would push all differences but clearly not.  Thinking about it a bit more over dinner, I realise my question was based on a bit of misunderstanding - i.e. the development branch wouldn't normally be a full clone of master.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Jan Cumps
    Jan Cumps over 4 years ago in reply to Andrew J

    Have you ever pushed and committed the development branch that Kraken generates for you?

    If you do that, it should appear upstream too.

    The same for your temporary feature branch.

    I checked Kraken website and the stream they use is very similar to what I use. Both they and I based many aspects on this blog post: https://nvie.com/posts/a-successful-git-branching-model/

     

     

    Almost all combinations are possible. I suggested one because it's easier to work if you have a known way of working.

    But there are other very good approaches.

    What you source your development branch from is something you decide yourself. I propose to source it from the master code. But it's a proposed way of working. Something that fits projects that already have a code base.

    I can see a valid situation if you start from an empty slate, to not have anything in master yet, and start your first commits in Develop and the feature branches based on develop, until you have a first release.

     

     

    A few scattered remarks:

    • I also see you mention gitflow. Do you mean the product gitflow? If yes, their workflow is also similar to what I propose here, but they offer richer commands.
    • I'd not work with local branches that have no server mirror. I have seen other people do it, and the GIT tutorials explain that. But I see it as a team tool - with all activity available to everyone by having all branches, also temporary ones, on the server.
    • Start with the command line if you want to understand git and github. Make a play github project, and start repeating the steps to get a local version, branching, etc, from your computer's prompt.
      You'll learn it in one focused day by cloning, branching, merging, pushing, committing. Because it tells you what it's doing in detail while executing the code.  When done, you can delete the github repo and your local playground.
      The Gui will make more sense then, because from what I see it's made to support a similar process.
    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
>
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube