Apnt 279
Apnt 279
Abstract
Teamwork is the basis of many modern microcontroller development projects. Often teams are distributed all
over the world and over various time zones. Synchronizing the development work is the main task for project
managers. As this work cannot be done by sending files via email from one location to another, Software
Version Control Systems (SVCS) are used. In the past, Concurrent Versions System (CVS) and Subversion
(SVN) have been popular for workflows with a centralized server infrastructure. Nowadays, more and more
decentralized workflows have been established, making use of a new SVCS called Git.
This application note describes how to integrate Git into µVision and how to establish a robust workflow for
version control of projects using Software Packs.
Contents
Abstract ...............................................................................................................................................................................................1
Introduction ........................................................................................................................................................................................1
Workflows ..........................................................................................................................................................................................2
Centralized Workflow .................................................................................................................................................................2
Using Git with µVision .....................................................................................................................................................................3
Project Files under Version Control ........................................................................................................................................3
Files that do not need to be monitored ..................................................................................................................................3
Configure µVision’s SVCS ...........................................................................................................................................................3
Version Control of Software Packs ..........................................................................................................................................4
Centralized Workflow Example ....................................................................................................................................................5
1. Initialize the Central Repository ......................................................................................................................................5
2. Clone a Repository from a Server ..................................................................................................................................6
3. Feature Work.......................................................................................................................................................................7
4. Manage Conflicts............................................................................................................................................................... 10
Conclusion ....................................................................................................................................................................................... 12
Appendix A: Software ................................................................................................................................................................... 12
Appendix B: Links........................................................................................................................................................................... 12
Introduction
Revision control is being used for a couple of years now in software development. In the past, centralized server
infrastructures have been used to track the changes in the source code of a microcontroller development
project. With the release of Git, decentralized VCS have become more and more popular.
Git, which is free software distributed under the terms of the GNU General Public License, was developed for
maintaining the Linux kernel. It became more and more popular and is now the de-facto standard in source
control management (SCM), another term for VCS.
This application note assumes that you have installed Git on your PC (refer to Appendix A: Software) and do
know how to use the Windows command shell (cmd.exe).
App Note 279 Copyright © 2015 ARM Ltd. All rights reserved
Using Git for Project Management with µVision 1 keil.com/appnotes/docs/apnt_279.asp
Workflows
Using Git, you can make use of various workflows when maintaining a software project:
Centralized workflow as known to users of CVS and SVN
Feature Branch workflow that adds a branch for every feature that is to be developed to the master
branch
Gitflow workflow using specific roles to different branches such as develop, feature, and release branch
Forking workflow that is a truly distributed workflow in the sense that every developer has his own fork
of the master branch and only one project maintainer is accepting commits to the master branch
This application note explains how to use µVision in a centralized workflow environment. Other workflows can
be realized as well using a mix of Git commands from within µVision and using the command line/GUI. For more
information on workflows, see Appendix B: Links.
Centralized Workflow
In a centralized work environment, there is usually a single collaboration model: the centralized workflow. A
central repository accepts code changes, and every developer synchronizes his work to it. This is just like using
SVN for example. However, using Git has a few advantages over the traditional SVN workflow.
First, it gives every developer an own local copy of the entire project. In this local environment, each developer
can work independently of all other colleagues. The local repository is used for commits and they can
completely forget about the original one until it's convenient for them.
Second, all developers can use Git’s robust branching and merging model. Git branches are designed to be fail-
safe when adding code and sharing changes between repositories.
The centralized workflow uses a central repository serving as the entry point for all project changes. The default
development branch is called ‘master’ and all changes are committed into this branch. No other branches are
required by this workflow:
1. Initialize the central repository
2. Clone a Repository from a Server
3. Feature work (stage/commit/push)
4. Manage Conflicts
App Note 279 Copyright © 2015 ARM Ltd. All rights reserved
Using Git for Project Management with µVision 2 keil.com/appnotes/docs/apnt_279.asp
Using Git with µVision
When done, press OK. Now, µVision is ready to use Git as the version control system.
App Note 279 Copyright © 2015 ARM Ltd. All rights reserved
Using Git for Project Management with µVision 3 keil.com/appnotes/docs/apnt_279.asp
Accessing µVision Project Files
When working with the SVCS menu, you can usually access files that are highlighted in the Project window of
µVision. For example, if you are clicking on the File Blinky.c in the Project window and you then go to the
SVCS menu, you will see the SVCS options for the Blinky.c file:
Packs… icon: This will open a new window that enables you to set the versions of all Software Packs:
App Note 279 Copyright © 2015 ARM Ltd. All rights reserved
Using Git for Project Management with µVision 4 keil.com/appnotes/docs/apnt_279.asp
Centralized Workflow Example
The following sections show an example for the centralized workflow. Other workflows can be derived from
the example. If the SVCS menu does not provide an entry for a required Git command, use either the GUI or
the command line instead.
App Note 279 Copyright © 2015 ARM Ltd. All rights reserved
Using Git for Project Management with µVision 5 keil.com/appnotes/docs/apnt_279.asp
create mode 100644 RTE/Device/LPC1857/RTE_Device.h
create mode 100644 RTE/Device/LPC1857/startup_LPC18xx.s
create mode 100644 RTE/Device/LPC1857/system_LPC18xx.c
create mode 100644 RTE/RTE_Components.h
Finally, push the files to the server:
C:\workdir\RTX_Blinky>git push -u origin master
Username/Password
Counting objects: 19, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (17/17), done.
Writing objects: 100% (19/19), 101.31 MiB | 104.00 KiB/s, done.
Total 19 (delta 0), reused 0 (delta 0)
To https://github.com/account/rtx_blinky.git
* [new branch] master -> master
Branch master set up to track remote branch master from origin.
Congratulations! You have created your first Git repository. For a more detailed description of the commands
that you have just used, go to section 3.
App Note 279 Copyright © 2015 ARM Ltd. All rights reserved
Using Git for Project Management with µVision 6 keil.com/appnotes/docs/apnt_279.asp
3. Feature Work
Now, you have a Git repository and a checkout or working copy of the files for that project. Working
on the project will create some changes and you will need to commit snapshots of those changes into
your repository from time to time.
Each file in the working directory is in one of the following two states: tracked or untracked. Tracked
files were already present in the last snapshot; they can be unmodified, modified, or staged. Untracked
files are everything else (for example build output logs etc.) – any files in the working directory that
were not present in the last snapshot and are not in the staging area. Cloning a repository for the first
time, all files will be tracked and unmodified.
While editing files, Git will recognize them as modified, because they have changed since the last
commit. Staging modified files and then committing all staged changes will make them be
tracked/unmodified again:
When opening the project, µVision automatically generates a uvguix.username file. This is marked as
not tracked (because it is not required).
Staging (Adding) an Untracked File
For this example, we will create a text file to will explain the usage of the project. The file will be
added to the working copy of the project and later committed to the origin.
In µVision, right-click on Target 1 and choose Add Group. New Group will be added in the
Project window. Click on New Group and a cursor should appear. Change the group name to
Documentation. Right-click on Documentation and choose Add New Item to Group
‘Documentation’. In the next window, click on Text File (.txt) and enter Abstract as the name. The
App Note 279 Copyright © 2015 ARM Ltd. All rights reserved
Using Git for Project Management with µVision 7 keil.com/appnotes/docs/apnt_279.asp
file will be added and opened in the editor. Enter any text that might seem fit. A git status will
show the file as untracked.
In order to begin tracking (or adding) Abstract.txt, use git add. Make sure that the file is highlighted
in the Project window and then go to SVCS Stage ‘Abstract.txt’:
App Note 279 Copyright © 2015 ARM Ltd. All rights reserved
Using Git for Project Management with µVision 8 keil.com/appnotes/docs/apnt_279.asp
Committing Changes
Before issuing the git commit command, check the project for unstaged files. A commit will only
accept staged files. Any created or modified files which have not yet been staged won’t go into this
commit. They will remain modified on the hard disk.
To commit, go to SVCS Commit staged changes. A window for entering the commit message
will open:
Enter the comment text and press OK. The Build Output window will show the success of the git
commit:
git commit -m C:\Users\User\AppData\Local\Temp\Sccs13
[master 1d1b0e6] C:\Users\User\AppData\Local\Temp\Sccs13
2 files changed, 1 insertion(+), 1 deletion(-)
create mode 100644 Abstract.txt
Pushing to the Repository
When the project has reached a point can be shared with others, it has to be pushed upstream (to the
repository server): git push [remote-name] [branch-name]. The built-in command in the
SVCS menu goes one step further. It uses git push origin master to push the master branch to
the origin server.
There are two prerequisites for this command to work properly:
1. You need to have write access to the server you are pushing to and
2. Nobody has pushed in the meantime. If this happens, your push will be rejected:
! [rejected] master -> master (fetch first)
error: failed to push some refs to
'https://github.com/account/rtx_blinky.git'
hint: Updates were rejected because the remote contains work that you
do not have locally. This is usually caused by another repository
pushing to the same ref. You may want to first integrate the remote
changes (e.g., 'git pull ...') before pushing again.
See the 'Note about fast-forwards' in 'git push --help' for details.
You’ll have to pull down first and incorporate any changes or rebase before you will be allowed
to push.
App Note 279 Copyright © 2015 ARM Ltd. All rights reserved
Using Git for Project Management with µVision 9 keil.com/appnotes/docs/apnt_279.asp
4. Manage Conflicts
Rebasing
The Git server’s central repository is the one that every developer will finally commit to. If a
developer’s local commits diverge from this repository, Git will refuse to push the changes. Before the
developer can publish on the server, all updated commits on the central repository need to be fetched
and the changes need to be rebased on top of them. This results in a linear history on the central
repository, just like in a SVN workflow.
If some of the changes are conflicting directly with upstream commits, Git will pause the rebasing
process. The developer can then manually resolve the conflicts. For generating commits and merging
conflicting files, Git uses the same git status and git add commands. This makes it easy to
manage merges.
To rebase, use SVCS Rebase. This will issue a git pull --rebase origin master that tells
Git to move all of your commits to the tip of the master branch after synchronizing it with the
changes from the central repository.
Rebasing transfers each local commit to the central repository’s master branch one at a time. Thus,
merge conflicts are caught on a commit-by-commit basis rather than by resolving all at once in a single
merge commit.
If two developers have worked on the same features (for example Blinky.c), the rebasing process
will generate conflicts. Git will pause the rebase (at the current commit) and the Build Output window
will show the following conflict message:
git pull --rebase origin master
From https://github.com/account/usb2
* branch master -> FETCH_HEAD
44af614..cdfdc12 master -> origin/master
First, rewinding head to replay your work on top of it...
Applying: C:\Users\User\AppData\Local\Temp\Sccs5
Using index info to reconstruct a base tree...
M Blinky.c
Falling back to patching base and 3-way merge...
Auto-merging Blinky.c
CONFLICT (content): Merge conflict in Blinky.c
Failed to merge in the changes.
Patch failed at 0001 C:\Users\User\AppData\Local\Temp\Sccs5
The copy of the patch that failed is found in:
c:/workdir/USB_test/.git/rebase-apply/patch
When you have resolved this problem, run "git rebase --continue".
If you prefer to skip this patch, run "git rebase --skip" instead.
To check out the original branch and stop rebasing, run
"git rebase --abort".
App Note 279 Copyright © 2015 ARM Ltd. All rights reserved
Using Git for Project Management with µVision 10 keil.com/appnotes/docs/apnt_279.asp
Also, the problem will be shown in the Editor window, for example:
Blaming
To get more information on the changes, you can use Git’s blame feature. While the main.c file is
highlighted in the Project window, go to SVCS Blame ‘Blinky.c’. This will initiate the GUI of Git
for Windows and show the details of the differences (hovering over the window will give more details
in the yellow boxes):
App Note 279 Copyright © 2015 ARM Ltd. All rights reserved
Using Git for Project Management with µVision 11 keil.com/appnotes/docs/apnt_279.asp
Pulling the Latest Version from the Server Repository
To pull the latest version from the remote server, go to SVCS Pull latest version from server.
This will initiate the git pull command:
git pull
From https://github.com/account/rtx_blinky
d8418bf..6fbcd97 master -> origin/master
Merge made by the 'recursive' strategy.
… Whatever has been changed …
A subsequent git push should show no errors:
git push origin master
To https://github.com/account/usb2.git
6fbcd97..e0c5dd3 master -> master
Conclusion
This application note has shown one way of using Git with µVision. As Git offers may ways of collaboration,
please consult the available literature that is stated below on how to use Git for a distributed workflow. Using a
combination of the commands from the GIT.SVCS file and the command line/Git GUI, you can use any workflow
supported by Git.
Appendix A: Software
To be able to use Git on a Windows PC and from within µVision, you need to install the following software:
Git for Windows: https://msysgit.github.io/
For MDK versions below 5.15, you need to add the µVision SVCS template file for Git which is part of
this application note’s ZIP file: www.keil.com/appnotes/docs/apnt_279.asp
Please copy the file to the µVision installation directory, for example C:\Keil_v5\UV4
Appendix B: Links
Git: http://git-scm.com
Git Book: http://git-scm.com/book/en/v2
Git server space providers: https://github.com/, https://bitbucket.org, https://about.gitlab.com/
Possible Workflows: www.atlassian.com/git/tutorials/comparing-workflows
Migrate from SVN to Git: www.atlassian.com/git/tutorials/migrating-overview
More information on Git replacing LF with CRLF: http://tinyurl.com/q3y7ohx
App Note 279 Copyright © 2015 ARM Ltd. All rights reserved
Using Git for Project Management with µVision 12 keil.com/appnotes/docs/apnt_279.asp