Developing FreeCAD with GitKraken: Difference between revisions

From FreeCAD Documentation
(GitKraken compatible external merge tools: Beyond Compare, FileMerge, Kaleidoscope, KDiff, Araxis, P4Merge; If none of the above options work for you, it's possible to specify External merge and diff tools within the configuration file ~/.gitconfig)
mNo edit summary
 
(16 intermediate revisions by 5 users not shown)
Line 1: Line 1:
<languages/>
<languages/>
<translate>
<translate>

== Foreword == <!--T:42-->

</translate>
{{TOCright}}
<translate>

<!--T:1-->
<!--T:1-->
FreeCAD uses [https://git-scm.com/ Git] to manage its source code. This document is a cursory introduction to [https://www.gitkraken.com/ GitKraken], a graphical user interface to Git. GitKraken is proprietary software that is free to use for non-commercial use; you don't need GitKraken to develop code for FreeCAD but many developers like it, and find it useful to manage their development. FreeCAD doesn't endorse GitKraken but we hope a guide like this one shows users how easy it is to set up the development environment and encourages more people to contribute.
FreeCAD uses [https://git-scm.com/ Git] to manage its source code. This document is a cursory introduction to [https://www.gitkraken.com/ GitKraken], a graphical user interface to Git. GitKraken is proprietary software that is free to use for non-commercial use; you don't need GitKraken to develop code for FreeCAD but many developers like it, and find it useful to manage their development. FreeCAD doesn't endorse GitKraken but we hope a guide like this one shows users how easy it is to set up the development environment and encourages more people to contribute.


<!--T:34-->
For more information on general Git usage from the command line see [[Source code management|Source code management]], and the online [https://git-scm.com/book/en/v2 Pro Git] book. To compile FreeCAD see [[Compiling|Compiling]].
For more information on general Git usage from the command line see [[Source code management|Source code management]], and the online [https://git-scm.com/book/en/v2 Pro Git] book. To compile FreeCAD see [[Compiling|Compiling]].


Line 13: Line 21:
== Setting up Git development == <!--T:4-->
== Setting up Git development == <!--T:4-->


<!--T:35-->
There are different ways to download GitKraken depending on your operating system. In Linux distributions, sometimes you can get it from the package manager.
There are different ways to download GitKraken depending on your operating system. In Linux distributions, sometimes you can get it from the package manager.


<!--T:5-->
<!--T:5-->
<ol>
<ol>
<li> Download GitKraken.</li>
<li>Download GitKraken.</li>
<li> In your web browser go to: {{URL|https://github.com/FreeCAD/FreeCAD}}.</li>
<li>In your web browser go to: {{URL|https://github.com/FreeCAD/FreeCAD}}.<br>
<li> Click the '''Fork''' button. This will clone the {{incode|FreeCAD/FreeCAD}} repository to your own account. In other words the URL to access your fork will be:
</translate>
<pre>
https://github.com/GITUBUSERNAME/FreeCAD.git
</pre></li>
<translate>
<!--T:6-->
<li> Open GitKraken, go to {{MenuCommand|File → Clone Repo}}, and enter this address.</li>
</translate>
[[File:GitKraken-Clone-Repo-dialogue.png]]
<translate>
<!--T:7-->
<li> GitKraken will now {{incode|git clone}} your personal repository.<br>


</translate>
Please read the difference between [https://stackoverflow.com/questions/9257533/what-is-the-difference-between-origin-and-upstream-on-github#9257901 origin vs. upstream] remote repository. Essentially, your fork of FreeCAD is the {{incode|origin}} repository, while the official FreeCAD repository is {{incode|upstream}}. You now need to set the upstream accordingly.</li>
[[File:Github-Fork-button.png]]
<li> Go to {{MenuCommand|File → Open Terminal}}, or press the {{KEY|Alt}}+{{KEY|T}} combination in your keyboard. Enter the following to set up your {{incode|upstream}} remote repository.
</translate>
<translate>

<pre>
<!--T:45-->
git remote add upstream https://github.com/FreeCAD/FreeCAD.git
</pre></li>
</li>
<li>Click the '''Fork''' button. This will clone the {{incode|FreeCAD/FreeCAD}} repository to your own account. In other words the URL to access your fork will be:
<translate>

<li> Now check the remote branches you have set:
</translate>
</translate>
<pre>
<pre>
https://github.com/GITHUBUSERNAME/FreeCAD.git
git remote -v
</pre>
</pre>
<translate>
<translate>

<!--T:8-->
<!--T:6-->
You should see something like this in the terminal:
</li></translate>
</li>
<li>Open GitKraken, go to {{MenuCommand|File → Clone Repo}}, and enter this address.<br>
<pre>

origin https://github.com/foobar/FreeCAD (fetch)
</translate>
origin https://github.com/foobar/FreeCAD (push)
[[File:GitKraken-Clone-Repo-dialogue.png]]
upstream https://github.com/FreeCAD/FreeCAD.git (fetch)
<translate>
upstream https://github.com/FreeCAD/FreeCAD.git (push)

</pre>
<!--T:7-->
<translate>
<!--T:9-->
</li>
<li>GitKraken will now {{incode|git clone}} your personal repository.
<li> Switch back to GitKraken interface. On the left side of the screen you will see a sidebar with a section labeled '''Local'''; double click on the {{incode|master}} branch so you switch to it. In the command line, this is equivalent to

<pre>
<!--T:36-->
Please read the difference between [https://stackoverflow.com/questions/9257533/what-is-the-difference-between-origin-and-upstream-on-github#9257901 origin vs. upstream] remote repository. Essentially, your fork of FreeCAD is the {{incode|origin}} repository, while the official FreeCAD repository is {{incode|upstream}}. You now need to set the upstream accordingly.</li>
<li>Locate the sidebar in Gitkraken. There is a '''Local''' and '''Remote''' section. Local refers to your local branches. Remote refers to remote repositories and their branches. Lets add the FreeCAD repo as a remote. In the '''Remote''' section click the {{Button|+}} (as illustrated in the image below).<br>

</translate>
[[File:Gitkraken-remote-sidebar.png]]
<translate>

<!--T:46-->
</li>
<li>An '''Add Remote''' dialog will open. Click the Github symbol (1). In the '''Github repo''' field (2) find the {{incode|FreeCAD/FreeCAD}} and click on it. In the '''Name''' field, type {{incode|upstream}}. Then click the {{Button|Add Button}}.<br>

</translate>
[[File:Gitkraken-add-remote-dark.png|400px]]
<translate>

<!--T:9-->
</li>
<li>The dialog will close and switch back to GitKraken main interface. This time find the '''Local''' section in the sidebar; double click on the {{incode|master}} branch so you switch to it. In the command line, this is equivalent to

</translate>
<pre>
git checkout master
git checkout master
</pre></li>
</pre>
<translate>
<li> Click on the '''Push''' icon on the top right side of the interface. This will push your '''Local master''' to your '''Remote origin master'''</li>

<!--T:47-->
</li>
<li>Click on the '''Push''' icon on the top right side of the interface. This will push your '''Local master''' to your '''Remote origin master'''</li>
</ol>
</ol>


== Deciphering the GitKraken interface == <!--T:10-->
== The GitKraken interface == <!--T:10-->


<!--T:11-->
<!--T:11-->
Line 76: Line 98:
| Local master || Your local branch of the FreeCAD master branch, indicated by the '''blue''' line in the screenshot.
| Local master || Your local branch of the FreeCAD master branch, indicated by the '''blue''' line in the screenshot.


<!--T:38-->
The item is highlighted in '''green''', meaning that the branch is currently active ({{incode|git checkout}}).
The item is highlighted in '''green''', meaning that the branch is currently active ({{incode|git checkout}}).
|-
|-
Line 94: Line 117:
<translate>
<translate>


{{Caption|GitKraken interface showing three local branches including a local {{Emphasis|master}}, and remote {{incode|origin}} and {{incode|upstream}} repositories, each of which have a master and release branches.}}
<!--T:14-->
<!--T:14-->
{{Caption|GitKraken interface showing three local branches including a local {{Emphasis|master}}, and remote {{incode|origin}} and {{incode|upstream}} repositories, each of which have a master and release branches.}}
In the image, the remote the '''Local master''' and '''Remote origin master''' branches are three commits behind the '''Remote upstream master''', that is, the official FreeCAD source code. This is indicated by the icons being three steps behind in the chain that represents the commit history of the master branch. See [[Developing_FreeCAD_with_GitKraken#Rebasing|Rebasing]] to update the branches that are behind.
In the image, the remote the '''Local master''' and '''Remote origin master''' branches are three commits behind the '''Remote upstream master''', that is, the official FreeCAD source code. This is indicated by the icons being three steps behind in the chain that represents the commit history of the master branch. See [[Developing_FreeCAD_with_GitKraken#Rebasing|Rebasing]] to update the branches that are behind.


Line 102: Line 125:
<!--T:16-->
<!--T:16-->
* Checkout the '''Local master''' branch by double clicking on it ({{incode|git checkout master}})
* Checkout the '''Local master''' branch by double clicking on it ({{incode|git checkout master}})
* Move the mouse to the last upstream commit, right click, and choose '''Rebase master on upstream/master''' ({{incode|git pull upstream master}})
* Move the mouse to the last upstream commit, right click, and choose '''Rebase master onto upstream/master''' ({{incode|git pull upstream master}})
* Now press the '''Push''' button ({{incode|git push origin master}}). This pushes from your '''Local master''' to the '''Remote origin master'''.
* Now press the '''Push''' button ({{incode|git push origin master}}). This pushes from your '''Local master''' to the '''Remote origin master'''.


Line 109: Line 132:
<translate>
<translate>


<!--T:39-->
{{Caption|Rebasing a local master updates it so that it matches the contents of the upstream master.}}
{{Caption|Rebasing a local master updates it so that it matches the contents of the upstream master.}}


Line 123: Line 147:


<!--T:21-->
<!--T:21-->
[https://help.github.com/articles/about-pull-requests/ Pull requests] (PRs) are necessary to merge the code in a branch in your local repository with the code in the {{incode|upstream}} repository. To summarize the process, once you've modified your branch, you need to push it to your GitHub fork ({{incode|origin}}, {{URLn|https://github.com/GITUBUSERNAME/FreeCAD.git}}), and from there make a pull request to {{incode|upstream}}. GitKraken saves you some clicks to easily create pull requests instead of using GitHub's interface.
[https://help.github.com/articles/about-pull-requests/ Pull requests] (PRs) are necessary to merge the code in a branch in your local repository with the code in the {{incode|upstream}} repository. To summarize the process, once you've modified your branch, you need to push it to your GitHub fork ({{incode|origin}}, {{URLn|https://github.com/GITHUBUSERNAME/FreeCAD.git}}), and from there make a pull request to {{incode|upstream}}. GitKraken saves you some clicks to easily create pull requests instead of using GitHub's interface.


<!--T:23-->
<!--T:23-->
Line 140: Line 164:
<!--T:25-->
<!--T:25-->
* GitKraken then opens up another dialog asking the repositories and branches to merge, and the direction (from and to).
* GitKraken then opens up another dialog asking the repositories and branches to merge, and the direction (from and to).
:You normally want to merge from the remote '''origin <your-branch-name>''' ({{incode|GITUBUSERNAME/FreeCAD}}) to the remote '''upstream master''' branch ({{incode|FreeCAD/FreeCAD}}). Be sure to enter a good title for the pull request, and write a more descriptive paragraph if your changes are significant. Consult the official documentation of [https://support.gitkraken.com/working-with-repositories/pull-requests GitKraken] for more information.
:You normally want to merge from the remote '''origin <your-branch-name>''' ({{incode|GITHUBUSERNAME/FreeCAD}}) to the remote '''upstream master''' branch ({{incode|FreeCAD/FreeCAD}}). Be sure to enter a good title for the pull request, and write a more descriptive paragraph if your changes are significant. Consult the official documentation of [https://support.gitkraken.com/working-with-repositories/pull-requests GitKraken] for more information.
</translate>
</translate>
[[File:Gitkraken-How-to-PR-Github-Dialog-breakdown.png]]
[[File:Gitkraken-How-to-PR-Github-Dialog-breakdown.png]]
Line 155: Line 179:


<!--T:30-->
<!--T:30-->
Squashing is when you have several commits you want to condense down in to one commit. From the [https://support.gitkraken.com/working-with-files/commits#squashing-commits GitKraken manual]:
As a revision control system Git encourages making many commits to keep track of your changes; however, if you have too many small changes the commit history may look a bit messy. Squashing is condensing various commits into only one commit. From the [https://support.gitkraken.com/working-with-commits/squash/ GitKraken manual], squashing is available for commits that meet the following requirements:
* You need to select at least two commits to squash.
Squashing is available for commits that meet the following requirements:
* The youngest commit, by commit date, is also the current HEAD commit.
* Selection contains more than one commit
* Genealogically consecutive.
* The youngest commit (by commit date) is also the current HEAD commit
* Genealogically consecutive
* Chronologically consecutive.
* The oldest commit in the list has a parent.
* Chronologically consecutive
* The oldest commit in the list has a parent
If all these conditions are met, the Squash option appears when you right click the commit node.
See screencast at: https://support.gitkraken.com/img/documentation/working-with-files/commits/squash.gif


<!--T:40-->
== Follow other FreeCADers branches == <!--T:31-->
If all these conditions are met, the '''Squash''' option appears when you right click the commit node. See [https://support.gitkraken.com/img/documentation/working-with-files/commits/squash.gif Squash.gif]

== Following other FreeCAD repositories == <!--T:31-->


<!--T:32-->
<!--T:32-->
'''Remotes''' are forked repositories of FreeCAD/FreeCAD by fellow FreeCADers. You can use Gitkraken to follow how FreeCAD devs code and commit to their own branches before they send git Pull Requests to the main FC repo.
You can use GitKraken to follow the personal FreeCAD forks of other developers; in this way you can see how they write code and commit changes to their own branches before they submit pull requests to the upstream {{incode|FreeCAD/FreeCAD}} repository.
# In the left side panel next to the '''Remote''' category, press the '''+''' sign.
Here is how you can follow other users:
# A dialogue will come up to enter the name of the repository that you want to add. Recommended remotes are from the main FreeCAD developers and known contributors: wmayer, yorikvanhavre, ickby, sliptonic, kkremitzki, etc.
# In the left side panel there is a '''Remotes''' category. Press the '''+'''
# Press '''Add Remote'''.
# A dialogue will come up that can give you the option to choose which remote you want to follow. Recommended remotes are: wmayer, yorikvanhavre, ickby, sliptonic, kkremitzki etc....

# Choose 'Add Remote'
<!--T:41-->
Whenever new commits are made or branches are rebased by said user you will see it represented in the gui.
Now whenever new commits are made, or branches are rebased, by the authors of those repositories, you will see their commit history in a graphical way.
</translate>[[File:Gitkraken-add-remote.gif]]
</translate>
[[File:Gitkraken-add-remote.gif]]
<translate>
<translate>


<!--T:33-->
== Related == <!--T:43-->

[[Category:Developer Documentation]]
<!--T:44-->
* [[Source code management]]
* [[Developing FreeCAD with KDevelop]]

</translate>
</translate>
[[Category:Developer Documentation{{#translation:}}]]
{{clear}}
[[Category:Developer{{#translation:}}]]
[[Category:3rd Party{{#translation:}}]]
{{Userdocnavi}}

Latest revision as of 09:42, 22 March 2022

Other languages:

Foreword

FreeCAD uses Git to manage its source code. This document is a cursory introduction to GitKraken, a graphical user interface to Git. GitKraken is proprietary software that is free to use for non-commercial use; you don't need GitKraken to develop code for FreeCAD but many developers like it, and find it useful to manage their development. FreeCAD doesn't endorse GitKraken but we hope a guide like this one shows users how easy it is to set up the development environment and encourages more people to contribute.

For more information on general Git usage from the command line see Source code management, and the online Pro Git book. To compile FreeCAD see Compiling.

Introduction

Git is a powerful revision control system commonly used to track computer code development. Although it is a complex system, you usually only need some background information on how it works, and to know a few terminal commands. A graphical user interface (GUI) eases the learning curve. GitKraken is a proprietary program that is free to use for non-commercial use that runs on the Electron framework, which means it is cross platform and can be used the same in Linux, MacOS, and Windows.

Setting up Git development

There are different ways to download GitKraken depending on your operating system. In Linux distributions, sometimes you can get it from the package manager.

  1. Download GitKraken.
  2. In your web browser go to: https://github.com/FreeCAD/FreeCAD.
  3. Click the Fork button. This will clone the FreeCAD/FreeCAD repository to your own account. In other words the URL to access your fork will be:
    https://github.com/GITHUBUSERNAME/FreeCAD.git
    
  4. Open GitKraken, go to File → Clone Repo, and enter this address.
  5. GitKraken will now git clone your personal repository. Please read the difference between origin vs. upstream remote repository. Essentially, your fork of FreeCAD is the origin repository, while the official FreeCAD repository is upstream. You now need to set the upstream accordingly.
  6. Locate the sidebar in Gitkraken. There is a Local and Remote section. Local refers to your local branches. Remote refers to remote repositories and their branches. Lets add the FreeCAD repo as a remote. In the Remote section click the + (as illustrated in the image below).
  7. An Add Remote dialog will open. Click the Github symbol (1). In the Github repo field (2) find the FreeCAD/FreeCAD and click on it. In the Name field, type upstream. Then click the Add Button.
  8. The dialog will close and switch back to GitKraken main interface. This time find the Local section in the sidebar; double click on the master branch so you switch to it. In the command line, this is equivalent to
    git checkout master
    
  9. Click on the Push icon on the top right side of the interface. This will push your Local master to your Remote origin master

The GitKraken interface

For more information consult the GitKraken Getting started guide.

Local indicates your local machine
Local master Your local branch of the FreeCAD master branch, indicated by the blue line in the screenshot.

The item is highlighted in green, meaning that the branch is currently active (git checkout).

Local <branch-name> Any other branches on your local machine. In the screenshot you can see branches called editor_fixes and editor_fixes_typos
Remote indicates a remote repository, for example in GitHub
Remote upstream The official FreeCAD repository https://github.com/FreeCAD/FreeCAD, indicated by the green line in the screenshot.
Remote origin Your personal fork of FreeCAD, https://github.com/YourGitHubUsername/FreeCAD, indicated by the red line in the screenshot.

GitKraken interface showing three local branches including a local master, and remote origin and upstream repositories, each of which have a master and release branches.

In the image, the remote the Local master and Remote origin master branches are three commits behind the Remote upstream master, that is, the official FreeCAD source code. This is indicated by the icons being three steps behind in the chain that represents the commit history of the master branch. See Rebasing to update the branches that are behind.

Rebasing

  • Checkout the Local master branch by double clicking on it (git checkout master)
  • Move the mouse to the last upstream commit, right click, and choose Rebase master onto upstream/master (git pull upstream master)
  • Now press the Push button (git push origin master). This pushes from your Local master to the Remote origin master.

Rebasing a local master updates it so that it matches the contents of the upstream master.

Branches

Branches are a feature that makes Git powerful compared to other revision systems. Branches aren't complete forks, but rather define snapshots where a version of the code starts diverging from the master branch. Whenever you want to modify the FreeCAD code, first create a branch, then make changes, and then merge your commits back to the master branch. With Git it is simple to create, merge and delete branches when you no longer need them. Please read Branching and Merging to understand more about this process in GitKraken.

  1. Make sure you currently have the master branch active (double click on it, git checkout master). In GitKraken the Local master branch should be highlighted in green.
  2. Click the Branch button to create a new branch and enter its new name (git checkout -b new-name-of-your-branch).

Making pull requests

Pull requests (PRs) are necessary to merge the code in a branch in your local repository with the code in the upstream repository. To summarize the process, once you've modified your branch, you need to push it to your GitHub fork (origin, https://github.com/GITHUBUSERNAME/FreeCAD.git), and from there make a pull request to upstream. GitKraken saves you some clicks to easily create pull requests instead of using GitHub's interface.

Steps in GitKraken:

  • Find you local branch on the interface and make sure it's active (double click on it).
  • Right click the branch name and find the option to Push <your-branch-name> and start a pull request.
GitKraken will open a dialog that asks you to confirm the repository which your branch will use to pull and push. It will then push your local branch to that remote repository.

  • GitKraken will ask you what you want to call the remote branch. The default name is the same name that the branch has locally in your computer.

  • GitKraken then opens up another dialog asking the repositories and branches to merge, and the direction (from and to).
You normally want to merge from the remote origin <your-branch-name> (GITHUBUSERNAME/FreeCAD) to the remote upstream master branch (FreeCAD/FreeCAD). Be sure to enter a good title for the pull request, and write a more descriptive paragraph if your changes are significant. Consult the official documentation of GitKraken for more information.

Resolving merge conflicts

GitKraken has a special merge conflict tool that is only accessible in the GitKraken Pro version. However, there are workarounds to use external tools for merging.

Squashing commits

As a revision control system Git encourages making many commits to keep track of your changes; however, if you have too many small changes the commit history may look a bit messy. Squashing is condensing various commits into only one commit. From the GitKraken manual, squashing is available for commits that meet the following requirements:

  • You need to select at least two commits to squash.
  • The youngest commit, by commit date, is also the current HEAD commit.
  • Genealogically consecutive.
  • Chronologically consecutive.
  • The oldest commit in the list has a parent.

If all these conditions are met, the Squash option appears when you right click the commit node. See Squash.gif

Following other FreeCAD repositories

You can use GitKraken to follow the personal FreeCAD forks of other developers; in this way you can see how they write code and commit changes to their own branches before they submit pull requests to the upstream FreeCAD/FreeCAD repository.

  1. In the left side panel next to the Remote category, press the + sign.
  2. A dialogue will come up to enter the name of the repository that you want to add. Recommended remotes are from the main FreeCAD developers and known contributors: wmayer, yorikvanhavre, ickby, sliptonic, kkremitzki, etc.
  3. Press Add Remote.

Now whenever new commits are made, or branches are rebased, by the authors of those repositories, you will see their commit history in a graphical way.

Related