-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Add source control best practices guide #6917
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
sirishapadmasekhar
wants to merge
4
commits into
ros2:rolling
Choose a base branch
from
sirishapadmasekhar:add-source-control-best-practices
base: rolling
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
934e5ab
Add source control best practices guide
sirishapadmasekhar efb6677
Wrap lines to satisfy documentation style checks
sirishapadmasekhar c228f68
Address review feedback for source control best practices
sirishapadmasekhar 9751abc
Merge branch 'rolling' into add-source-control-best-practices
fujitatomoya File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
132 changes: 132 additions & 0 deletions
132
source/The-ROS2-Project/Contributing/Source-Control-Best-Practices.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,132 @@ | ||
| .. redirect-from:: | ||
|
|
||
| Source-Control-Best-Practices | ||
| Contributing/Source-Control-Best-Practices | ||
|
|
||
| Source Control Best Practices | ||
| ============================= | ||
|
|
||
| .. contents:: Table of Contents | ||
| :depth: 2 | ||
| :local: | ||
|
|
||
| Introduction | ||
| ------------ | ||
| This page highlights source control considerations commonly encountered when contributing to ROS 2 projects. | ||
| It is not intended to replace Git documentation. | ||
| Instead, it focuses on ROS-specific recommendations and references to external resources where appropriate. | ||
|
|
||
| Avoid committing generated and temporary files | ||
| ---------------------------------------------- | ||
|
|
||
| ROS 2 workspaces generate build artifacts that should generally not be committed to source control. | ||
|
|
||
| Sources of generated, temporary, and backup files | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
|
||
| Colcon workspace artifacts | ||
| ~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| Common workspace artifacts include: | ||
|
|
||
| .. code-block:: text | ||
|
|
||
| build/ | ||
| install/ | ||
| log/ | ||
|
|
||
| The ``build/``, ``install/``, and ``log/`` directories are generated by ``colcon build`` as part of a ROS 2 workspace. | ||
| These directories are typically created at the workspace level rather than inside individual repositories. | ||
|
|
||
| If these directories appear within a repository, they should not be committed to source control. | ||
|
|
||
| Python-generated files | ||
| ~~~~~~~~~~~~~~~~~~~~~~ | ||
|
|
||
| Python generates several temporary files, including the ``__pycache__/`` directory and files ending with ``*.pyc``, ``*.pyo``, and ``*.pyd`` when you run the program. | ||
| None of these files should ever be committed to a repository. | ||
|
|
||
| IDE configuration files | ||
| ~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
|
||
| Editors and IDEs often generate project-specific or user-specific configuration files. | ||
|
|
||
| Common examples include: | ||
|
|
||
| .. code-block:: text | ||
|
|
||
| .vscode/ | ||
| .idea/ | ||
|
|
||
| Many ROS 2 repositories ignore editor-specific files such as ``.vscode/`` and ``.idea/``. | ||
| Contributors should avoid committing personal editor configuration unless it is explicitly required by the repository. | ||
|
|
||
| Editor temporary and backup files | ||
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
|
||
| Some editors like Vim create backup files ending with ``~`` (for example, ``test.py~``) and temporary files ending with ``*.swp``, ``*.swo``, and similar. | ||
| These should never be committed to the repository. | ||
|
|
||
| Operating system files | ||
| ~~~~~~~~~~~~~~~~~~~~~~ | ||
|
|
||
| Operating systems may generate metadata files such as ``.DS_Store`` (macOS) and ``Thumbs.db`` (Windows). | ||
| These files should never be committed to a repository. | ||
|
|
||
| Before committing changes, review the files included in a commit. | ||
| Ensure that generated and temporary files have not been added accidentally. | ||
|
|
||
| Gitignore placement options | ||
| --------------------------- | ||
|
|
||
| Repository ``.gitignore`` | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
|
||
| Use the following rule of thumb when deciding whether a file belongs in a repository-specific ``.gitignore`` or your global ``.gitignore``. | ||
|
|
||
| If the file will be present on every developer's computer, put it in the repository ``.gitignore``. | ||
|
|
||
| Global ``.gitignore`` | ||
| ^^^^^^^^^^^^^^^^^^^^^ | ||
|
|
||
| A global gitignore can help prevent accidentally committing files that are unrelated to a repository, such as operating system metadata files or personal editor configuration. | ||
|
|
||
| Git supports configuring a global excludes file through the ``core.excludesfile`` configuration option. | ||
|
|
||
| For example: | ||
|
|
||
| .. code-block:: console | ||
|
|
||
| $ git config --global core.excludesfile ~/.gitignore_global | ||
|
|
||
| A global gitignore is useful for excluding files that are specific to a developer's machine or editor and are not intended to be committed to any repository. | ||
|
|
||
|
sirishapadmasekhar marked this conversation as resolved.
|
||
| Credential helpers | ||
| ------------------ | ||
|
|
||
| When contributing to ROS 2 repositories, contributors will often interact with Git hosting services such as GitHub. | ||
|
|
||
| SSH keys and Git credential helpers can simplify authentication. | ||
| Avoid repeatedly entering credentials when pushing changes or interacting with remote repositories. | ||
|
|
||
| Rather than duplicating setup instructions here, refer to the official GitHub and Git documentation for recommended configuration steps. | ||
|
|
||
| Developing on shared robots | ||
| --------------------------- | ||
|
|
||
| When developing on a shared robot or other remote system, an SSH agent can cache your unlocked SSH key for the current session. | ||
| This avoids repeatedly entering your SSH key passphrase when interacting with Git repositories over SSH. | ||
| Refer to the official GitHub SSH documentation for setup instructions. | ||
|
|
||
| Additional resources | ||
|
sirishapadmasekhar marked this conversation as resolved.
|
||
| -------------------- | ||
|
|
||
| * `Git ignore documentation <https://git-scm.com/docs/gitignore>`_ | ||
| * `GitHub gitignore templates <https://github.com/github/gitignore>`_ | ||
| * `GitHub SSH documentation <https://docs.github.com/en/authentication/connecting-to-github-with-ssh>`_ | ||
| * `Git credential storage documentation <https://git-scm.com/book/en/v2/Git-Tools-Credential-Storage>`_ | ||
|
|
||
| Example ROS 2 ``.gitignore`` files include: | ||
|
|
||
| * `rclcpp <https://github.com/ros2/rclcpp/blob/rolling/.gitignore>`_ (minimalistic example) | ||
| * `rviz <https://github.com/ros2/rviz/blob/rolling/.gitignore>`_ (reasonable example) | ||
| * `message_filters <https://github.com/ros2/message_filters/blob/rolling/.gitignore>`_ (extensive example) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.