Git (and Python) workflow when contributing to the official KiCad libraries

Jump to navigation Jump to search

This description of the Git (and Python) workflow when contributing to the official KiCad libraries is intended as a simple walk-through how-to for users new to KiCad and Git but who have enough know-how to open a terminal and use the command line.

Contributing to KiCad

Instead of effort being wasted by any number of different designers recreating their own versions of symbols, footprints or 3d models of unknown quality, by contributing to the official libraries, the combined effort will help these to grow benefiting all KiCad users.[1]

The KLC

The KiCad Library Convention (KLC) is a set of requirements for contributing to the official KiCad libraries.[2]

The things that are really important still need to be hand checked. This is the main work that library maintainers do. For example the pin numbers, names and types still needs to be compared to the datasheet, for footprints a dimension check is also required.[1]

KiCad utilities

Before making a pull request use the KiCad utilities (Python scripts) to check whether the parts you are considering submitting are KLC compliant. They mainly check stuff that is only important for having a consistent library.[1]

Travis CI

On GitHub Travis CI checks KLC compliance of footprint files and symbol libraries.

Usage

See the README.md file. Run these in a terminal window using Python

Use pcb/check_kicad_mod.py to check KLC compliance of footprint files.

Use schlib/checklib.py to check KLC compliance of schematic symbol libraries.

GitHub

GitHub simply hosts a Git server and provides a nice web interface.[3] The official KiCad libraries are hosted on GitHub.

One time SSH key setup

Create a fork (e.g. footprints)

At https://github.com/KiCad/kicad-footprints click Fork at the top right, to fork your own copy of KiCad/kicad-footprints to your GitHub account.[4]

Note that https://github.com/KiCad/kicad-footprints is referred to as "upstream" and your fork https://github.com/YOUR-USERNAME/kicad-footprints as "origin".[5]

Git Bash

To go to your home directory, enter with no other text

cd

To list the files and folders in your current directory, enter

ls

To go into one of your listed directories, enter

cd your_listed_directory

To go up one directory, enter

cd ..

[4]

Git

Git is an open source distributed version control system (VCS) and is available for multiple OS. It is available for free.[6][7][8]

The command line is the only place you can run all Git commands, most of the GUIs implement only a partial subset of Git functionality for simplicity. If you know how to run the command-line version, you can probably also figure out how to run the GUI version, while the opposite is not necessarily true.[9]

Initial setup

The first thing to do is to set your user name and email address, every Git commit will use this information. Use the git config command with the --global option this only needs to be done once:[10][11]

To setup the user name

git config --global user.name "John Smith"

To setup the user email address

git config --global user.email john@example.com

To check the user name

git config user.name

To check the user email address

git config user.email

Usage (e.g. for footprints)

For help on common Git commands, enter:

git --help

For the manual page on a particular command, (e.g. add) enter:

git --help add

To have the files in your fork on your computer, create a clone of your fork locally on your computer with:

git clone https://github.com/YOUR-USERNAME/kicad-footprints

The commands below are done in the folder of your working copy of the fork (# marks a comment).

To update:

git pull

Add the official KiCad repo as another remote. This takes care of keeping all branches up-to-date between your fork ("origin") and the KiCad repo ("upstream"). This only needs to be done once:[10]

git remote add upstream https://github.com/KiCad/kicad-footprints.git

Make a separate pull request (PR) for each separate library, (e.g. Button_Switch_THT.pretty vs. Potentiometer_THT.pretty). To do this you need to have one branch per contribution:

git fetch upstream # get the state of the official repo
git checkout upstream/master # change to the current head of the official repo
git checkout -b new_sensible_branch_name # create a new branch from that state
git push --set-upstream origin new_sensible_branch_name # push that new branch to github

Make your changes then:

git add --all # or git add list_of_files
git commit -m "descriptive_commit_message"
git push # push your changes online

Go to https://github.com/YOUR-USERNAME/kicad-footprints and click the "Compare & pull request" button to do the PR. Complete the form and click "Create pull request".

If you then are requested to do some changes you would need to checkout the correct branch and then do your changes:

git checkout branch_connected_to_pull_request # without -b switch

Do your changes:

git add --all # or again git add file_list
git commit -m "descriptive_commit_message"
git push # push your fixes to GitHub (will automatically appear in the pull request)

[3][12]

Further reading

  • Pro Git by Scott Chacon, Ben Straub Paperback, Apress, Nov. 2014, ISBN 9781484200773

References

  1. ^ a b c Contributing Parts - Selection, KiCad.info Forums, Sep 2018
  2. ^ KiCad Library Convention, v3.0.17
  3. ^ a b Git and the libraries for newbies, KiCad.info Forums, Feb 2019
  4. ^ a b Fork a repo, GitHub Help
  5. ^ What is the difference between origin and upstream on GitHub?, Stack Overflow
  6. ^ Git homepage
  7. ^ Version Control Software in 2014: What are Your Options?, Shaumik Daityari, 22 April 2014
  8. ^ PCB version control and notes, EEVblog forum, May 2015
  9. ^ Getting Started - The Command Line, Pro Git by Scott Chacon and Ben Straub
  10. ^ a b Setting up a repository, atlassian.com
  11. ^ Getting Started - First-Time Git Setup, git-scm.com
  12. ^ Workflow for better KiCad library contribution (Git + KiCad), KiCad.info Forums, May 2018

External links

KiCad

Tutorials

Python

Git

Tutorials

Github

Tutorials