The concept of managing repositories with Git involves linking your Local and Remote repositories, so that you are able to use Git commands to send and receive changes from both locations, enabling you to create backups of your work and collaborate with others. 

Instructions: Complete the following activity to practice linking your local with your remote repository.

🎯 When you've completed the activity, don't forget to click the 'Mark as done' button at the top left of this page. This helps track your course progress and ensures you receive your course badge without delay.


There are multiple approaches to linking the local with the remote repository. We've outlined Dave's personal favourite approach below: 

  1. From GitHub, copy the SSH address of the my-repo you created in Exercise 3 to your clipboard.
  2. Now switching to the terminal on your personal machine, navigate to the directory where your local repository is stored. Link the remote GitHub repository to your local repository with the SSH address of the repository (i.e. something like  git@github.com:username/my-repo.git ) using the following command: 
     
     
     
     

    $ cd my-repo/
    ~/my-repo$ git remote add origin <insert your SSH address of repository>

     

  3. Rename the current branch on your local repository to 'main' (ensures your local branch matches GitHub’s naming conventions, preventing mismatch errors when pushing for the first time): 
     
     
     
     

    ~/my-repo$ git branch -M main

     

  4. Finally, create the connection between the local main branch and the remote main branch by pushing your local branch to the remote (origin) GitHub repo, making it visible to collaborators and accessible remotely:
     
     
     
     

    ~/my-repo$ git push -u origin main
    Enumerating objects: 9, done.
    Counting objects: 100% (9/9), done.
    Delta compression using up to 16 threads
    Compressing objects: 100% (6/6), done.
    Writing objects: 100% (9/9), 903 bytes | 903.00 KiB/s, done.
    Total 9 (delta 1), reused 0 (delta 0)
    remote: Resolving deltas: 100% (1/1), done.
    To github.com:username/my-repo.git
     * [new branch]      main -> main
    Branch 'main' set up to track remote branch'main' from 'origin'.

     

If you're feeling stuck completing this exercise, please feel free to pose questions or consult the Discussion Forum.