Source code management

Our main source code management tool is git. This article explains how to use it and how some general rules apply in the case of FreeCAD. You are highly advised to learn how git works first (there are a lot of tutorials and docs available for git on the internet) before working with the FreeCAD source code.

There are also many good graphical clients to git, such as git-cola, that make the whole process of managing git repositories easier.

Source Code Access
Everybody can access and get a copy of the FreeCAD source code, but only the FreeCAD project managers have write access to it. You can get a copy of the code, study it and modify it as you wish, but if you make a change that you wish to see included in the official source code, you need to ask for a pull request on the pull requests section of the FreeCAD forum.

Official GitHub Repo
An easy way to start with the FreeCAD source code is using the official FreeCAD repository at https://github.com/FreeCAD/FreeCAD

You can start simply by using the "fork" button on top of the above page. This will create a copy of the FreeCAD repository on your own GitHub account. The general procedure is as follows:
 * 1) Sign up for a GitHub account
 * 2) Go to the FreeCAD repo:  https://github.com/FreeCAD/FreeCAD
 * 3) Press the "Fork" button
 * 4) On your machine, clone your newly created FreeCAD fork:
 * git clone https://github.com//FreeCAD.git
 * 1) Make your specific changes to the source code
 * 2) Create a new branch
 * 3) Checkout that new branch
 * 4) Commit your changes to that new branch
 * 5) Push that new branch to your GitHub repo

You can also start normally, without using the "fork" button:
 * 1) Clone the FreeCAD code with git:
 * git clone https://github.com/FreeCAD/FreeCAD.git
 * 1) Make your specific changes to the code
 * 2) Create a new branch
 * 3) Checkout that new branch
 * 4) Commit your changes to that new branch
 * 5) Create an account on a public git server (GitHub, GitLab, etc...)
 * 6) Push your branch to that server

Important Note': If you have code you wish to see merged into the FreeCAD source code, please post a note in the Pull Requests section of the FreeCAD forum.

Access rules
We will give everyone interested in participating write access to the git repository as long as you stay away from master branch (tip).

Authentication
The read-only access does not prompt for a password.

The read/write access uses your ssh password or ssh key to authorize your access. To perform write operations, your project administrator must have granted you write access to the repository.

Note: In all examples below, "USERNAME" represents your GitHub user account.

Setting your git username
Users should commit to their project repository using their GitHub username. If that is not already set globally, you can set it locally for the current Git repository like this: git config user.name "YOUR NAME" git config user.email "USERNAME@users.noreply.github.com"

You can now use some combination of "git add" and "git commit" commands to create one or more commits in your local repository.

Alternative repositories
The beauty of git is that everybody can clone a project, and start modifying the code. Several frequent collaborators of the FreeCAD project have their own git repository, where they build up their work before it is ready to be included in the official source code, or simply where they experiment new ideas. In certain cases, you might want to clone your FreeCAD code from one of these, instead of the official repos, to benefit from the changes their users did.

Be warned, though, that this is at your own risk, and only the official repository above is fully guaranteed to work and contain clean code.

It is also possible to attach several remote repositories to a same local FreeCAD git code, using the "git remote" command. This is useful to keep in sync with the master code branch, but keep an eye on the work of different developers.

Git Development Process
First of all never develop on the master branch! Create a local branch for development. You can learn how to do this here.

Branching
An important feature of Git is that it is extremely easy to work with branches and merge them together. Best practices recommend to create a new branch whenever you want to work on a new feature. Creating a branch is done with: git branch myNewBranch git checkout myNewBranch

or, both operation in one: git checkout -b myNewBranch

you can always check in which branch you are with: git branch

Committing
Once you did some work, you commit them with: git commit -a

Unlike SVN, you need to specifically tell which files to commit (or all with the -a option). Your text editor will open to allow you to write a commit message.

Publishing your work on your GitHub repository
After done some changes on your local branch and commit it (this means commit locally) you can push your repository to the server. This opens your branch to the public and allows the main developers to review and integrate your branch into master. git push my-branch

Writing good commit messages
You should try to work in small chunks. If you cannot summarize your changes in one sentence, then it has probably been too long since you have made a commit. It is also important that you have helpful and useful descriptions of your work. For commit messages, FreeCAD has adopted a format mentioned in book Pro Git (see ).

Short (50 chars or less) summary of changes More detailed explanatory text, if necessary. Wrap it to about 72 characters or so. In some contexts, the first line is treated as the subject of an email and the rest of the text as the body. The blank line separating the summary from the body is critical (unless you omit the body entirely); tools like rebase can get confused if you run the two together. Further paragraphs come after blank lines. - Bullet points are okay, too - Typically a hyphen or asterisk is used for the bullet, preceded by a   single space, with blank lines in between, but conventions vary here

If you are doing a lot of related work, it has been suggested here that one should make as many commits large or small as makes sense for what you are working on using the short one sentence commit messages. When you want to merge, do a git log master..BRANCH and use the output as a basis for your quality commit message. Then when you merge to master use the --squash option and commit with your quality commit message. This will allow you to be very liberal with your commits and help to provide a good level of detail in commit messages without so many distinct descriptions.