Introduction to Version Control

Apr 10 2024 · Git 2.44, Terminal, GitHub Desktop

Lesson 03: Using GitHub for Version Control

Push & Pull Demo

Episode complete

Play next episode

Next
Transcript

Here’s a new, private repository. It has license and README.md files. You can clone this repository once you make a Personal Access Token.

Click the icon at the upper right to access your profile menu. Near the bottom, select “Settings”. On the “Profile” page, scroll down and select “Developer settings”. Then, select that you want a fine-grained token.

This account already has a token. I can click it to see some information about it, but I can’t see the token value itself. Back at the tokens list, click the “Generate new token” button. Give the token a nickname and a description. For this token, you want it to access a single repository. Alternatively, you could choose up to 50 of my repositories or give the token to all current and future repositories.

Now, in the “Repository permissions” section, scroll down to “Contents” and grant read and write permissions. Then, scroll to the bottom and click “Generate token”.

Click this button with the two boxes to copy this token to the clipboard. Anytime you see that button in GitHub, it’s for copying the related text to your clipboard.

With the token copied to the clipboard, you can return to your repository to get ready to clone. When you click the “Code” button, GitHub gives you the URL or offers to clone using GitHub Desktop. There’s also the button to copy to the clipboard. Don’t click it; you’ve got your token on the clipboard, and you can only have one thing on the clipboard at a time. Type the URL or save your token somewhere, like in Notes or on a Sticky.

Now, you can safely copy the URL. Open the terminal and navigate to where you want to copy the repository. Git creates a folder with the same name as the remote repository and copies the entire repository into it. You can navigate into the new directory and type git config -l to see that there are entries for the remote and that it’s called “origin”.

Open GitHub Desktop and find “Clone repository” under the file menu. GitHub Desktop doesn’t use personal access tokens; it uses your actual GitHub credentials. Click “Sign in”, and GitHub tells you it will open your browser to authenticate you. Once you’ve authorized GitHub Desktop in your browser, you’re sent back to the app and shown a list of all your repositories. You can select any repository from the list to clone it. To save it somewhere other than the default, click the “Choose” button for a standard file picker window. Now, you can clone the repository.

You’ve authorized GitHub Desktop using OAuth, so GitHub Desktop has access to your account until you revoke it.

You can create a new repository locally and link it to a remote, all in the GitHub app, without going to the website separately.

Select “File” and “New repository”. You see a form almost identical to the one on the website. The repository is created after you complete the form. It hasn’t been created on the GitHub website, though. To do that, click this “Publish repository” button and complete this form.

GitHub Desktop can only work with the origin remote. If you must work with multiple remotes, you need to use the terminal to push and pull from those remotes.

For any repository on your computer not linked to a remote on GitHub, you can select “File” and “Add local repository”. Then, browse to the repository and click the “Add repository” button.

Click “Publish repository” like before and complete the form to push it to GitHub.

Notice that when using GitHub Desktop, you must push each branch separately. If you want to push all branches, switch to the terminal.

See forum comments
Cinema mode Download course materials from Github
Previous: Linking a Repository to GitHub Next: Collaborating on GitHub