Setting Up GitHub Desktop & Creating Our First Repository
Note: This section assumes you already have an account on GitHub. If not, follow the steps outlined in “Creating Your First Repository on GitHub” section in Lesson 3, “Using GitHub for Version Control”.
Click the Sign in to GitHub.com button. This will open a browser window where you can use your GitHub credentials to log into GitHub. If you have not already logged into GitHub in your browser, you will be presented with the following window.
Enter your credentials and click the green Sign in button to access the select user page. Note: If you are signed into GitHub.com in your browser, you will be taken directly to the select user page.
Click the green Continue button for the user you want to use with GitHub Desktop.
Next, you will be asked to authorize GitHub Desktop with your GitHub account and allow access to all repositories, your data on GitHub, and workflows. Click the Green Authorize desktop button to continue.
You will be asked if you want to allow the website to open GitHub Desktop. Click Allow or Always Allow based on your preferences. GitHub Desktop should appear after clicking Allow.
Here you are asked to configure the name and email to use when creating commits. You can use the information that is already stored in your GitHub account or provide a name and email address to use. This information will be used commit messages.
This screen is equivalent to the following command line git statements.
git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"
Click the blue Finish button to continue.
Creating Your Homework Repository
After providing a user name and email address, GitHub Desktop provides the options to create repositories, clone a repository from the Internet, or add existing repositories from your local drive. Click the Create a New Repository on your Local Drive… button.
On the Create a New Repository dialog, you can give your new repository a name, description, and local path on your computer. The Name and Local Path fields are required; all other fields are optional. In the screenshot above, the “Initialize this repository with a README” option is checked, and the “Git Ignore” field contains “Swift”. The README file is a Markdown file that provides details of the repository, and the .gitignore is a file that tells Git what files to ignore in the project. These files are typically temporary or preference files that are not required for building the project. Click the blue “Create Repository” button to continue.
This screen is equivalent to creating a folder for your repository and initializing it. Adding a .gitignore, license will need to be done manually.
mkdir myCoolApp
cd myCoolApp
git init
Publishing the Repository to GitHub
Finally, we arrive at the repository info screen. At the top of the window, we see the currently open repository. In this case, it is the repository we created in the last step. After the current repository, the current branch is listed. When a new repository is made, there is only one branch, main. After the current branch, there is an action to publish the repository to GitHub.
Currently, our repository is only on our local machine. Clicking ‘Publish repository’ will create a remote repository on GitHub and link it as a remote in our local repository.
When clicking Publish repository, a dialog will appear with the name and description fields prepopulated with the local repository’s name and description. They can be set to different values; however, it is good to keep them the same to prevent confusion later on. The Keep this code private option is checked by default. This will make the remote repository private. Private repositories will not appear in search results and can only be accessed by users who have been granted access to the repository. We recommend that you keep your homework repository private throughout the boot camp.
Clicking the Publish Repository button will create the remote repository on GitHub, and you will see some changes in GitHub Desktop.
You will note that the button for ‘Publish repository’ has been changed to ’Fetch origin’. Fetch origin will get the latest changes from the remote repository (named origin by default). When working with a team, you will want to update your branch with the latest changes before pushing your changes to the remote repository.
The steps are the equivalent of creating a repository on GitHub and using the URL for the repository to set the local repository’s remote and pushing the local commits to the remote.
git remote add origin <remote_repository_URL>
git push -u origin main
Let’s review what we have done.
- Created a new local repository on our machine
- Created a remote repository on GitHub and linked it as a remote in our local repository
Next we will create a branch for our homework.