# Connecting Remote and Local Repos A few weeks ago we downloaded `git` and learned the basics. For the coming weeks, we will be working `git` and Github. Thus, we must link our **local** `git` repositories (the ones initialized directly on our computers) to our **remote** Github repositories (stored on [Github](https://github.com/)). Follow the instructions below to set up a Github account, link it to your local `git`, and make our first commit to a remote repository. **Note:** If you already have a Github account and it is configured to `git` (through a PAT or SSH key), feel free to skip to "Create a new remote repository". ## Making a Github account If you do not already have a Github account, please make one [here](https://github.com/). Use whichever email you want. For best practices, use the email you set when configuring `git`. (If you forgot, you can check in your Terminal/Powershell by typing `git config --list`.) ## Generate a Personal Access Token After you make your Github account, generate a **Personal Access Token (PAT)**. This token will be used **in place of your Github password**. (This is a common authentication method. Some people prefer to use SSH keys instead. If you feel comfortable setting up with SSH, be my guest.) (**IMPORTANT:** after this token is generated, copy the token and paste it somewhere safe (e.g. a notes app). You will not see this token again) ### Steps to generate a PAT 1. Click your profile icon in the top right corner ![Screenshot 2025-10-29 at 9.42.22 AM](https://hackmd.io/_uploads/rk3lV6kk-e.png) 2. Select **Settings**. 3. In settings, select **Developer Settings** (the last option listed) 4. In Developer Settings, select **Personal Access Tokens** > **Token (classic)** 5. Click **Generate New Token (classic)** 6. Name it something ("298-nix" or whatever you want) 7. Select an expiration date (or no expiration) (no expiration is more convenient but less secure. Setting an expiration will require you to repeat this process once it expires) 8. Check/select the following scopes: `repo` (for private repos), `workflow` (optional) 9. Click "Generate Token" 10. Copy the generated token and paste it somewhere! You'll use it again soon. ## Create a new remote repository 1. Still on Github, manual create a new repository. Name the repository `lastname_298Nix` (replace `lastname` with your last name). 2. Make the repository **private**. 3. Click "Make Repository". You will be directed to your new repository's page. 4. Click the green "Code" button, select the HTTPS tab, and copy the HTTPS address. It should look something like this: `https://github.com/your-username/myproject.git` ## Clone your remote repository locally There are a bunch of ways to connect local repos to remote ones. The "cleanest" is to make the remote repository *first*, and then **clone** that repository to your local file system. (Of course, initializing a local repository and adding it to a remote repository is also perfectly acceptable.) 1. open your Terminal and enter Bash/Ubuntu (Mac users type "bash", PC/Ubuntu users type "wsl") 2. `cd` into your cpsc298Nix directory 3. Enter the following command (replace `<HTTPS>` with the HTTPS address you just copied): ``` git clone <HTTPS> ``` This creates the **local** copy of your remote repo. 4. If you `ls`, you will see the new local repo (as a directory) named `lastname_298Nix`. `cd` into the repo. 5. Make a `README.md` (this could have been done when making the remote repo, but bear with me) ``` touch README.md ``` 6. Type the command `git status`. You will see that our local repo now has something that our remote repo does not. In order to sync the two, we need to commit (and push) the changes we made in our local repo to our remote repo. **Execute the following commands** ``` git add README.md git commit -m "first commit" git push origin main ``` 7. Upon first `push` or `pull`, Git will ask you for credentials (username and password). * Username: Provide your Github username * Password: Copy your PAT (from wherever you stored it) and paste it in place of a password 8. Cache your Git credentials so you do not have to enter your username and password every time: ``` git config --global credential.helper store ``` This way, Git securely stores your PAT in `.git-credentials` 9. Refresh your remote repository in Github. You should see a `README.md` that didn't use to be there! ## Write/Add a `helloworld.sh` to your repo We have written Hello World scripts a lot of times this semester, so I will bore you with the same code again. 1. Write the script, change permissions, and test it (because it is not in the `bin` directory, we will have to revert to the classic `./helloworld.sh`). 2. Push to your remote repo (**Recall:** `add`, `commit`, `push`) 3. Check your remote repo (you will get an error message if the push wasn't successful, but it's fun to bask in the glory of pushing to remote). ## HW Deliverables (aka, what you submit to Canvas) I know that was a lot of steps. Now it's time to prove to me that you did them. 1. Add me as a collaborator to your Github Repo (because we set it to private, I cannot see it unless I am a collaborator) * go to your remote repository on Github * click "Settings" (settings to your repo, not settings to your profile) * Click "Collaborators" (it might ask you to enter your Github password to authentication) * Add me as a Collaborator (my username: holcombet) 2. In your **local** repository, take a screenshot of the output when you enter the command `git status` (to show you cloned remote to local) 3. On the Canvas Assignment "Setting up Github", submit: * the screenshot of your terminal * the link to your Github repository