Skip to content

👩🏻‍💻 🧑🏽‍💻 Subscribe and Join us on Substack to Get Full Access to Our Posts


How to upload your Xcode Project to Github – Tutorial

In this article, we will walk you through the process of setting up GitHub in Xcode and uploading your SwiftUI project to your GitHub account. The steps will include configuring GitHub in Xcode, creating a Git repository, and pushing code updates. Let’s dive in!

Step 1: Create a New Xcode Project

  1. Open Xcode and create a new SwiftUI project.
  2. Name your project. In this example, we’ll call it “Xcode To Github Demo App.”

Step 2: Add Your GitHub Account to Xcode

  1. In Xcode, navigate to Xcode > Settings (or Preferences, depending on your macOS version).
  2. Go to the Accounts tab.
  3. Click the + button to add a new account, and select GitHub.
  4. Enter your GitHub username.
  5. You’ll need a personal access token to authenticate. Let’s generate one.

Step 3: Generate a Personal Access Token on GitHub

  1. Log in to your GitHub account, tap on your profile icon and go to Settings.
  2. Scroll down and select Developer settings (on the left).
  3. In the left-hand menu, click Personal access tokens > Tokens (classic).
  4. Click Generate new token, and confirm by entering your GitHub password.
  5. Name your token (e.g., “Xcode”), and set an expiration date or choose No expiration.
  6. Check all the scopes to grant full access, then click Generate token.
  7. Copy the generated token.

Step 4: Link the Token with Xcode

  1. Go back to Xcode, paste the token in the Token field, and click Sign In.
  2. Now your GitHub account is linked to Xcode.

Step 5: Set Up Source Control in Xcode

  1. In Xcode, go to Settings > Source Control > Git.
  2. Set up your Author Name and Email (use your GitHub username and the email associated with your GitHub account).

Step 6: Create a New Git Repository and Push Project to Github

  1. Close the Settings window.
  2. Tap Command+2 to open Navigator’s Source Control and select Repositories.
  3. Tap on the Xcode To Github Demo App in repository and tap “Xcode To Github Demo App” Remote
  4. Choose the Github Account, Set repository name if needed, Set Visibility (Public or Private), write Description if needed
  5. Tap Create 
  6. Optional: If you don’t see Repository in your Navigator you can try to tap Integrate > New Git Repository to create one and after that follow the steps 1-5 of Step 6

Step 7: Check repository on Github

  1. Go Github > Your Repositories and check if the new repository appeared

Step 8: Make Changes and Commit Them

  1. Let’s make a simple change in the project:
    • For example, update the text in ContentView.swift from “Hello, World!” to “Hello Github”
  2. Go to Source Control > Commit, and you’ll see the change highlighted.
  3. Add a commit message (e.g., “Changed ContentView Message to Hello Github“), and click Commit.
  4. If it asks to Stage, tap Stage all and commit (You should stage changes before committing)

Step 9: Push the Commit to GitHub

  1. After committing the changes, go to Source Control > Push.
  2. Select the origin (by default, it’s the main branch).
  3. Leave include tags unchecked, we will discuss this checkbox later
  4. Click Push, and your changes will be uploaded to GitHub.

Step 10: Verify the Changes on GitHub

  1. Go to your GitHub repository and refresh the page.
  2. You should see the recent commits and changes in the project files.
  3. You should check Activity section of your project on Github to see the latest commit

How to Tag Your commit in Xcode and Provide a Version (e.g., 1.0.0) for your Commit

Tagging helps mark specific points in your project history, such as a release version.

  1. Go to Source Control > Branches.
  2. Right click on main and select Tag “main”
  3. Add version number, for example1.0.0 and a message
  4. Make some changes into your project
  5. Go to Integrate > Push and check include tags
  6. Go to Github > Releases > check tags

How to Fetch changes from Remote

  1. Go to Github into your Project repository and tap Create Readme file there
  2. Fill in Readme file with some text, for example:
    # README
    
    Demo App to show how to Connect Xcode Project to Github
    
    ## Overview
    
    Learn Daily
    
    ### Section header
    
    Some Section Text here
    
  3. Now go to Xcode and tap Pull to get changes from Github.

Understanding Staging, Amending, and Committing Changes

Xcode uses Git’s staging area to manage changes, allowing you to control exactly what goes into each commit. Here’s how to work with staging and amending:

What is Staging?

Staging means preparing specific changes to be included in your next commit. In Xcode:

  • Staged Changes: These are the changes you have selected to commit. They will be included in the next commit you make.
  • Unstaged Changes: These changes are not yet prepared for committing. You can choose to stage them by checking the boxes next to the file names in the commit window.

How to Stage Changes in Xcode:

  1. View the Changes: Go to Source Control > Commit to see the list of changed files.
  2. Stage the Files: Check the box next to each file you want to include in your commit.
  3. Unstage if Necessary: Uncheck any files you don’t want to commit yet.

Amending a Commit

Sometimes you need to make small changes to the last commit without creating a new commit. Here’s how to amend in Xcode:

  1. Make the Desired Changes: Modify the files you want to update.
  2. Go to the Commit Window: Source Control > Commit.
  3. Select “Amend Previous Commit”:
    • At the bottom of the commit window, you’ll see an option labeled “Amend Previous Commit.”
    • Check this box to modify the last commit instead of creating a new one.
    • Update the commit message if necessary, and click Commit.

Example Use Cases:

  • Staging: Useful for breaking larger changes into smaller, logical commits.
  • Amending: Helps fix mistakes in the last commit, such as forgetting a file or making a typo in the commit message.

This Post Has 0 Comments

Leave a Reply

Back To Top
Search

Get Latest App Development News, Tips and Tutorials

* indicates required