Source code management: Difference between revisions
(Changed orientation from SF to GitHub) |
Kkremitzki (talk | contribs) No edit summary |
||
Line 1: | Line 1: | ||
<translate> |
<translate> |
||
<!--T:1--> |
<!--T:1--> |
||
Our main source code management tool is [http://en.wikipedia.org/wiki/Git_%28software%29 git]. This article |
Our main source code management tool is [http://en.wikipedia.org/wiki/Git_%28software%29 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. |
||
<!--T:2--> |
<!--T:2--> |
||
There are also many good graphical clients to git, such as [http://github.com/git-cola/git-cola git-cola], that make the whole process of managing git repositories easier. |
There are also many good graphical clients to git, such as [http://github.com/git-cola/git-cola git-cola], that make the whole process of managing git repositories easier. |
||
== Access == <!--T:3--> |
== Source Code Access == <!--T:3--> |
||
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 [http://forum.freecadweb.org/viewforum.php?f=17 pull requests] section of the FreeCAD forum. |
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 [http://forum.freecadweb.org/viewforum.php?f=17 pull requests] section of the FreeCAD forum. |
||
<!--T: |
=== Official GitHub Repo === <!--T:5--> |
||
An easy way to start with the FreeCAD source code is using the official FreeCAD repository at |
|||
=== From Github === <!--T:5--> |
|||
An easy way to start with the FreeCAD source code is using the official FreeCAD repository on [http://www.github.com GitHub]. The previous Sourceforge git repository is now deprecated and used only for archival purposes. The official FreeCAD repo can be found at: |
|||
</translate> |
</translate> |
||
https://github.com/FreeCAD/FreeCAD |
https://github.com/FreeCAD/FreeCAD |
||
Line 23: | Line 20: | ||
# Go to the FreeCAD repo: https://github.com/FreeCAD/FreeCAD |
# Go to the FreeCAD repo: https://github.com/FreeCAD/FreeCAD |
||
# Press the "Fork" button |
# Press the "Fork" button |
||
# On your machine, clone your newly created FreeCAD fork: |
# On your machine, clone your newly created FreeCAD fork: |
||
#: <pre>git clone https://github.com/<GitHubusername>/FreeCAD.git</pre> |
|||
# Make your specific changes to the source code |
# Make your specific changes to the source code |
||
# Create a new branch |
# Create a new branch |
||
Line 32: | Line 30: | ||
<!--T:7--> |
<!--T:7--> |
||
You can also start normally, without using the "fork" button: |
You can also start normally, without using the "fork" button: |
||
# Clone the FreeCAD code with git: |
# Clone the FreeCAD code with git: |
||
#: <pre>git clone https://github.com/FreeCAD/FreeCAD.git</pre> |
|||
# Make your specific changes to the code |
# Make your specific changes to the code |
||
# Create a new branch |
# Create a new branch |
||
# Checkout that new branch |
# Checkout that new branch |
||
# Commit your changes to that new branch |
# Commit your changes to that new branch |
||
# Create an account on a public git server (GitHub, |
# Create an account on a public git server (GitHub, GitLab, etc...) |
||
# Push your branch to that server |
# Push your branch to that server |
||
Line 43: | Line 42: | ||
''Important Note''': If you have code you wish to see merged into the FreeCAD source code, please post a note in the [http://forum.freecadweb.org/viewforum.php?f=17 Pull Requests] section of the FreeCAD forum. |
''Important Note''': If you have code you wish to see merged into the FreeCAD source code, please post a note in the [http://forum.freecadweb.org/viewforum.php?f=17 Pull Requests] section of the FreeCAD forum. |
||
=== |
=== Access rules === <!--T:11--> |
||
To access a Git repository on sf.net, configure your Git client as follows : |
|||
<!--T:10--> |
|||
git://git.code.sf.net/p/free-cad/code (read-only) |
|||
ssh://USERNAME@git.code.sf.net/p/free-cad/code (read/write) |
|||
==== Access rules ==== <!--T:11--> |
|||
We will give everyone interested in participating write access to the git repository |
We will give everyone interested in participating write access to the git repository |
||
as long as you stay away from ''master'' branch (tip). |
as long as you stay away from ''master'' branch (tip). |
||
=== Authentication === <!--T:12--> |
|||
The read-only access does not prompt for a password. |
The read-only access does not prompt for a password. |
||
Line 63: | Line 55: | ||
<!--T:14--> |
<!--T:14--> |
||
'''Note:''' In all examples below, "USERNAME" represents your |
'''Note:''' In all examples below, "USERNAME" represents your GitHub user account. |
||
==== How to clone the repository ==== <!--T:15--> |
|||
You can simply clone your remote repository and get working: |
|||
</translate> |
|||
git clone ssh://USERNAME@git.code.sf.net/p/free-cad/code REPONAME |
|||
cd REPONAME |
|||
<translate> |
|||
<!--T:16--> |
|||
The first time you try connecting to the free-cad.git.sourceforge.net host, |
|||
you should see a message similar to the following: |
|||
</translate> |
|||
The authenticity of host 'git.code.sf.net (216.34.181.91)' can't be established. |
|||
RSA key fingerprint is 86:7b:1b:12:85:35:8a:b7:98:b6:d2:97:5e:96:58:1d. |
|||
Are you sure you want to continue connecting (yes/no)? |
|||
<translate> |
|||
<!--T:17--> |
|||
Before typing 'yes' to accept the host fingerprint, ensure the fingerprint is correct for the host. |
|||
You can find a listing of SSH host keys in the SSH Host Key Fingerprints list. If you receive a host |
|||
key warning, please contact the SourceForge.net team. |
|||
=== Setting your git username === <!--T:18--> |
|||
Users should commit to their project repository using their |
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: |
If that is not already set globally, you can set it locally for the current Git repository like this: |
||
</translate> |
</translate> |
||
git config user.name "YOUR NAME" |
git config user.name "YOUR NAME" |
||
git config user.email "USERNAME@users. |
git config user.email "USERNAME@users.noreply.github.com" |
||
<translate> |
<translate> |
||
<!--T:19--> |
<!--T:19--> |
||
Line 95: | Line 68: | ||
commits in your local repository. |
commits in your local repository. |
||
=== |
=== Alternative repositories === <!--T:20--> |
||
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. |
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. |
||
<!--T:21--> |
<!--T:21--> |
||
Be warned, though, that this is at your own risk, and only the |
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. |
||
<!--T:22--> |
<!--T:22--> |
||
Line 135: | Line 108: | ||
-a option). Your text editor will open to allow you to write a commit message. |
-a option). Your text editor will open to allow you to write a commit message. |
||
=== Publishing your work on |
=== Publishing your work on your GitHub repository=== <!--T:29--> |
||
After done some changes on your local branch and commit it (this means commit |
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 |
''locally'') you can push your repository to the server. This opens your branch |
||
Line 143: | Line 116: | ||
git push my-branch |
git push my-branch |
||
<translate> |
<translate> |
||
=== Publishing on another repository === <!--T:30--> |
|||
Git also allows you to merge branches from more than one repository. If you don't |
|||
have write access to the sourceforge hosted FreeCAD Git repository, you can also setup |
|||
an account on any other free Git host such as [https://github.com/ github] or |
|||
[http://gitorious.org/ gitorious] and tell other people to get your changes from there. |
|||
=== Writing good commit messages === <!--T:31--> |
=== Writing good commit messages === <!--T:31--> |
Revision as of 16:38, 6 February 2017
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:
- Sign up for a GitHub account
- Go to the FreeCAD repo: https://github.com/FreeCAD/FreeCAD
- Press the "Fork" button
- On your machine, clone your newly created FreeCAD fork:
git clone https://github.com/<GitHubusername>/FreeCAD.git
- Make your specific changes to the source code
- Create a new branch
- Checkout that new branch
- Commit your changes to that new branch
- Push that new branch to your GitHub repo
You can also start normally, without using the "fork" button:
- Clone the FreeCAD code with git:
git clone https://github.com/FreeCAD/FreeCAD.git
- Make your specific changes to the code
- Create a new branch
- Checkout that new branch
- Commit your changes to that new branch
- Create an account on a public git server (GitHub, GitLab, etc...)
- 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.
Developing
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 #Further Reading).
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.