Version Control Part 3 – Setting up for PSoC

To use GitHub with PSoc code requires a very specific set up, this is mostly due to how PSoC creates and manages files.

PSoC Creator has a default folder in Documents where project code is stored. Each workspace can host a number of projects. This tutorial commits the workspace, and therefore automatically includes all projects. Some PSoC users organizer their workspaces by keeping one workspace per microcontroller type.

First, create a new workspace in PSoC Creator by selecting “New project” under the “File” tab, and selecting “workspace” when prompted with the radio buttons that appear. Use the default location (C:/Users/UserName/Documents/PSoC Creator/) and specify a name for the workspace

Next, create a new project by using one of the existing template projects.

PSoC Creator for now.

Setting up the Repo and including a .gitignore

Open the folder in which the workspace was saved (C:\\Users\\UserName\\Documents\\PSoC Creator\\WorkspaceName) in Windows Explorer.

Right click within the folder and select “Git Bash here” to open a git terminal.

To initialize the workspace as a git repo, enter git init. Next, download the .gitignore and put the .gitignore file in the same folder.

On the GitHub UI, create a new repository, but do not initialize it with a README.md, .gitignore, license, or any other option. Just a name, such as PSoC Workspace. Click create repository.

Follow the instructions that appear to push the local repository to the newly created repository on GitHub. Make sure to include the .gitignore. Instead of adding all the files manually, type git add ., this means to add all files in the directory. It is better practice to use purposeful selection of files (e.g. git add FolderName/* which adds all files in a folder, or git add FileName.fileExtension which adds a single file) to avoid accidentally adding files that are not caught by the .gitignore, or committing secrets (passwords, API tokens, etc.) that should never be publically available.

Pulling from the repo

Other users can clone and pull changes, but must rebuild the project in order for it to work on their systems. The .gitignore omits all build files and pertinent workspace information that is custom to each user.

Editing the .gitignore

There is a very likely chance as the semester proceeds that the .gitignore will need to be modified for files in certain folders that are related to compilation and therefore (currently) not included. The following describes relevant symbols in .gitignores. The .gitignore file downloaded has notes on how to edit the file to include files after being ignored, or to identify specific files to be included.

Symbols

  • /# comments out the line
  • /* is a wildcard. If placed in front of a folder or name, any number of alphanumerics can precede it. If placed at the end of a folder or name, any number of alphanumerics can follow after it
  • / folder structures end with a forward slash even if on a Windows System
  • ! means to include a file or folder after it has been excluded

Further Explanation of the .gitignore edits

If edits occur in the Generated_Source/ folder, to include specific files the .gitignore must be edited following the *Generated_Source/ line with the following: !*Generated_Source/FolderName/FileToInclude.* This may not be the only structure. The example listed refers to a custom USB_audio, thus, the added line looks like !*Generated_Source/PSoC4/USB_audio.*. This line indicates that all files in Generated Souree in PSoC4 that begin with USB_audio must not be ignored.

If other optional items such as datasheets are necessary to be commented then remove the preceding ```#` from the line to uncomment it.

Commit the changes to ensure they come into effect. Files that are present before a .gitignore is implemented (and they are marked to be ignored) will still be present in the repository and tracked. It is good practice to implement a .gitignore before development begins. To resolve this enter git rm -r --cached <To Be Ignored> where To Be Ignored refers to a file or folder structure (Folder/ to ignore a directory entirely Folder/* to ignore the folder’s contents) that needs to be removed. When you commit, the discrepancy should be resolved.