Linking Xcode and GitHub
I love that you can commit and push changes to GitHub right from within Xcode. Trust Apple to keep you within their ecosystem, and their IDE! I decided to write the steps to remind myself on how to do it. I am also assuming that you have a GitHub account. If not, head over to GitHub and create one.
- When creating your new project in Xcode, ensure you check the box that creates a new GitHub repository before you hit that Create button. If you were too eager to begin your project and forgot to do this, click on the Source Control menu and select “create Git repositories”. Follow the steps.
2. Click on the Xcode menu and then preferences. Here we want to link our GitHub account to Xcode. Once connected, the link is pretty seamless. Bottom left of this window you’ll find a + button. Click this and select GitHub from the list of accounts. Click Continue and you’re taken to another pop up window that asks for your GitHub account username. Fill this in, then we need to generate a token from your GitHub page…
3. Head over to GitHub and sign in. If you’re like me and have added a profile picture, click on the mini you up in the top right-hand side and select settings. Scroll down and click on developer settings on the left side of the screen, then click on Personal access tokens and generate new token.
You will be asked to write down a note which will remind you what this token will be used for. I called mine Xcode! To ensure you can commit changes and push to GitHub, you must select the first 3 tick boxes — repo, write:packages and read:packages.
4. Click generate token. Your new token will display on the screen. Copy this and paste into the token input box in Xcode.
5. Back in Xcode select the second icon on the top left menu bar. If you expand the main folder you will see 4 folders: Branches, Tags, Stashed Changes and Remotes. Right click on remotes folder and select ‘New [project name] Remote…’. This new window is where you create your repo. You can add a description and choose to have your repo public or private etc. Once you hit create, you will have created your repository, and will be visible on your GitHub account.
6. Once you have added to your project, select Commit from the Source Control menu. Here you will be able to write a comment and select the files you wish to include to GitHub. I would recommend ensuring all files are clicked. Click Commit.
7. Finally, to submit these to GitHub, you need to push to the repository. Again in the Source Control menu, select Push. Ensure you are pushing local changes to the origin/main and hit Push.
We’re done!
Thanks for reading! I hope this helps someone out there. It helps me to write things down so I understand them better.