Git Basics¶
Some Commands¶
git clone: Clone a git repositorygit config --global user.name "Sanyika": Set usernamegit config --global user.email "sanyika@gggmail.com": Set emailgit init: Initialize a local repositorygit add <file>: Add a filegit status: Check current statusgit commit -m "My beautiful commit": Commit with a messagegit push: Push changesgit pull: Pull changes, update local repositorygit branch <new_branch_name>: Create a new branchgit checkout <branch_name>: Switch to a branchgit checkout -- .: Discard all unstaged changes locally. In newer git versions,git restore .works similarly.git merge <branch_name>: Merge a branch into the current branch

Source: link
Terminology¶
- Local repository: The local working repository, e.g.,
~/ros2_ws/src/my_repo - Remote repository: Usually an online remote backup repository, e.g.,
github.com/my_name/my_repo
Preparations¶
If you haven't done so already, register on GitHub.
Using the Template¶
Navigate to https://github.com/sze-info/ros2_cpp_template.
Here, use the green button to create a package named my_awesome_package with your user:

Then you will see this page, where you need to fill in the repository name and click the green button to create the repository:

Clone Your Package with git clone¶
If your GitHub username is mycoolusername and the repository (and package) name is my_awesome_package, you can do it like this:
cd ~/ros2_ws/src
git clone https://github.com/mycoolusername/my_awesome_package
git clone https://github.com/horverno/my_awesome_package
Replace Everything in VS Code¶
cd ~/ros2_ws/src/my_awesome_package
code .
- Replace
ros2_cpp_templatewithmy_awesome_package - Replace
sze-infowithmycoolusername - Replace
todoas appropriate

Build¶
The package can now be built:
cd ~/ros2_ws/
colcon build --packages-select my_awesome_package
my_awesome_package package has been built.
Run¶
Run in the usual way:
source ~/ros2_ws/install/local_setup.bash
ros2 launch my_awesome_package launch_example1.launch.py
Track Changes with git status¶
When we replaced the package name, several files were modified:
cd ~/ros2_ws/src/my_awesome_package
git status
The same in VS Code looks like this:
Update Remote Repository with git push¶
We want to add all changes to the commit:
git add .
Fill in the commit message:
git commit -m "Initial commit of my_awesome_package"
Actually push the changes to GitHub servers:
git push
In VS Code, this is simpler: Commit, then Sync Changes:
Update Local Repository with git pull¶
In case the local version is not the latest, the remote stored on GitHub can be updated:
Sources¶
- docs.ros.org/en/humble/Tutorials/Beginner-Client-Libraries/Creating-Your-First-ROS2-Package.html
- docs.ros.org/en/humble/Tutorials/Beginner-Client-Libraries/Writing-A-Simple-Cpp-Publisher-And-Subscriber.html
- docs.ros.org/en/humble/Tutorials/Beginner-Client-Libraries/Writing-A-Simple-Py-Publisher-And-Subscriber.html