🔧 Git Repo Setup#

Purpose#

Setup GIT repositories and access on the Master.

Note

Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.

Create a Repository within the GitHub Classroom#

  1. If you don’t already have a GitHub account, create one. It’s best if your username is something identifiable (e.g., stanbaek).

  2. Once your account is ready, go to the ECE387 Classroom.

  3. Your afacademy email address has been preloaded to make joining easy. While I prefer your school email address, you may use another email if desired. For this, click Skip to the next step:

    ../_images/GitClassroom_SelectIdentifier.png
  4. Select Accept this assignment.

  5. Navigate to your repository and note the repository URL. Save this link—it’s the easiest way to check if your repository is updated.

  6. Go to Settings and change your repository name to ece387-lastname (e.g., ece387-baek).

    Important

    Please name your repository as ece387-lastname (all lowercase). This makes it easier for instructors to locate your repository.

Set Up GitHub SSH Key on Master#

This section assumes you already have a GitHub account.

  1. Create an SSH key for your GitHub account by running the following command. Use the same email as your GitHub login:

    $ cd  
    $ ssh-keygen -t ed25519 -C "your_email@email.com"  
    
  2. When prompted to specify a file path, press Enter to accept the default location (~/.ssh/id_ed25519).

  3. Start the ssh-agent in the background and add your SSH private key:

    $ eval "$(ssh-agent -s)"  
    $ ssh-add ~/.ssh/id_ed25519  
    
  4. Open the public key using your favorite terminal-based text editor. This step is easier via an SSH connection from a GUI-based desktop machine, as it allows you to copy the public key to your GitHub account:

    $ nano ~/.ssh/id_ed25519.pub  
    
  5. Copy the entire contents of the file. Maximize the window to ensure you don’t miss anything, including the GitHub email.

  6. Open a web browser and log in to your GitHub account.

  7. In the top-right corner of any page, click your profile photo, then select Settings:

    ../_images/ssh1.png
  8. In the settings sidebar, click SSH and GPG keys:

    ../_images/ssh2.png
  9. Click New SSH key:

    ../_images/ssh3.png
  10. In the Title field, provide a descriptive label for the key, such as master0.

  11. Paste the copied key (from the .pub file) into the Key field.

  12. Click Add SSH key to save it.

Clone Repository to Your Master#

  1. On the Master, open your GitHub repository and copy the repository address using the SSH mode:

    ../_images/GitClone.png
  2. Open a terminal and create a workspace source folder:

    $ mkdir -p ~/master_ws/src/  
    $ cd ~/master_ws/src  
    
  3. Clone your repository:

    $ git clone git@github.com:ECE387/ece387_lastname.git  
    
  4. Update your Git email address and name:

    $ git config user.email "you@example.com"  
    $ git config user.name "FirstName LastName"  
    
  5. Move into your repository you just cloned:

    $ cd ece387-lastname  
    
  6. Use the touch command to create an empty file called COLCON_IGNORE. This file ensures that this directory will be ignored when compiling ROS packages.

  7. Run the following command to append your full name and section to a file named README.md. Since the file does not exist, it will be created automatically:

    $ echo "# Your full name, Section" >> README.md  
    
  8. Verify that the file was created correctly by running:

    $ cat README.md  
    

    If the file was created successfully, you should see output similar to the following:

    ../_images/GitCreateReadmeFile.png
  9. Commit and push your changes to your GitHub repository:

    $ git add -A 
    $ git commit -m"initial commit"
    $ git push  
    

Setup Upstream Repository#

  1. Open a Terminal and navigate to your local repository, such as

    $ cd  ~/master_ws/src/ece387_lastname
    
  2. Ensure your local repository is up to date with the remote GitHub repository by running

    $ git pull 
    
  3. Verify that all your local changes have been committed and pushed to the remote GitHub repository by running

    $ git status 
    

    If your repository is clean, you should see the following message:

    On branch main
    No commits yet
    nothing to commit (create/copy files and use "git add" to track)
    

    If you see uncommitted changes, make sure to commit and push them to the remote repository before proceeding.

  4. Check your current remote repositories by typing

    git remote -v
    

    You should see two lines showing that origin points to your remote repository on GitHub for both fetching and pushing.

  5. Add the instructor’s repository as additional remote source by running

    $ git remote add upstream https://github.com/ECE-387/labs.git
    $ git config pull.rebase true
    
  6. Verify that the upstream repository has been added successfully by typing

    git remote -v
    

    You should now see two additional lines indicating upstream is the original repository you forked from.

    ../_images/GitAddUpstream.gif
  7. If the instructor updates the code, you will be notified. To get the latest updates from the upstream repository, run

    git pull upstream main
    
  8. By default, when you push or pull your code, origin will be used, which points to your own GitHub repository.

    ../_images/FetchUpstream.png
    Image is sourced from Stack Overflow

Create a Team Repository within GitHub Classroom#

Important

Only one person per group should complete these steps.

  1. Visit the GitHub Classroom Assignment.

  2. Click Create team.

  3. Select Accept this assignment.

  4. Navigate to your repository and go to Settings. Change your repository name to ece387-lastname_lastname (e.g., ece387-baek_pirate).

    Important

    Please name your repository as ece387-lastname_lastname (all lowercase). This makes it easier for instructors to locate your repository.

  5. Go to Settings > Collaborators and teams > Manage access.

  6. Invite your partners by entering their GitHub usernames.

  7. If you are using a different computer from the previous labs, go to this section to set up a new SSH key for the remote GitHub repository.

  8. Clone your repository. Ensure that the name of your local repository is ece387_ws by running:

    $ git clone git@github.com:ECE387/ece387_lastname_lastname.git ~/master_ws/src/ece387_ws