Moon Ha

performer-composer / researcher

Utilizing Git and GitHub

There are many ways to build a development environment on a Linux or Mac machine for developing hardware/software based on Raspberry Pi Pico, and there is no particular way that is the best. However, I found that using CLion and Segger’s J-Link debugger provides a streamlined experience, so I suggest my students try this. No matter which IDE and debugger you choose, it is essential to have a place to share code and ideas. Therefore, as part of the development environment, we need to learn how to use Git and GitHub to share code. Let’s figure out Git and GitHub first:

Package Management

In this article, I will use macOS and Ubuntu (Linux), and each operating system requires a package management system. For macOS, we will use Homebrew, and for Ubuntu, we will use APT (Advanced Packaging Tool). Homebrew installation details can be found at:

https://docs.brew.sh/Installation

APT is installed as the default package management system in Ubuntu, so you do not need to install it in most cases. Please update it using the following command in the terminal:

sudo apt update
sudo apt upgrade
Git and Github

Git is a distributed version control system designed for tracking changes in source code during software development, offering fundamental functionalities like branching, merging, and version history. On the other hand, GitHub is a web-based platform built around Git, providing a centralized hub for hosting repositories with additional collaboration features such as pull requests, issue tracking, and project management tools. While Git operates locally on a developer’s machine, GitHub serves as a hosting service that enhances collaboration, making it widely used for sharing, contributing, and managing code in both open-source and private projects.

We need to install both the Git and GitHub command-line tools as follows:

// for macOS
brew install git
brew install --cask github


// for Ubuntu
// installing git
sudo apt install git

// installing github 
// https://github.com/cli/cli/blob/trunk/docs/install_linux.md
Github Account

You need to create your GitHub account at github.com. You can access it through your web browser, but we will use it in our terminal to utilize the command-line interface.

// Login
gh auth login

Then, you will be prompted with the following prompts:

What account do you want to log into?

->GitHub.com

What is your preferred protocol for Git operations on this host?

->HTTPS

How would you like to authenticate GitHub CLI?

->Login with a web browser

Then, it will say “Press Enter to open github.com in your browser…”, so you need to press the Enter key to open the website. Please type in the code shown in your terminal, which looks like 0F7E-F6E4 or something similar.

Cloning Existing Repository

Let’s try to clone an existing repository onto your computer. I would suggest the following instructions. It will clone a repository that we will need to set up and test the Raspberry Pi Pico, J-Link debugger, and CLion.

// Go to your home directory.
cd

// Create a Dev directory.
mkdir Dev

// Clone a repository.
gh repo clone https://github.com/hamoonyoung/hello-pico

// Check if the repository was cloned.
ls hello-pico/

If you see the main.c and CMakeLists.txt files, you have successfully cloned the repository.

Other Commands

Here are a few useful commands that you may need it for near future. Please feel free to research and find other tutorials to learn how to use Git and Github effecively.

// Pull an existing repository from the command line
// git pull 'remote_name' 'branch_name'
git pull origin

// Push an existing repository from the command line
git init
git add .
git commit -m "Initial commit"
git remote add origin https://github.com/hamoonyoung/hello-pico.git
git push -u origin main

// Create a new repository on the command line
echo "# hello-pico" >> README.md
git init
git add README.md
git commit -m "First commit"
git branch -M main
git remote add origin https://github.com/hamoonyoung/hello-pico.git
git push -u origin main

Reply

Your email address will not be published. Required fields are marked *