Skip to content

Creating a Swift Project in XCode 6 and adding it to a git repo on BitBucket

June 18, 2014

I’m new to Swift, Xcode and Git and wanted to create a play area sample command line project that I could backup in a git in a private repo in BitBucket after a few failed starts, it turns out its actually quite easy when you do things in the required order… (I wanted more that just an Xcode Swift playground)

Instructions in XCode relate to version 6 Beta.

Connection to Bitbucket over SSH

I thought I’d try out using SSH so that I didn’t need to keep on entering the password (albeit that keychain may make this less painful to do).

Create a public/private key pair

For more detailed instructions see

Run the ssh-keygen command accepting the defaults and specify a long passcode when prompted to generate a public private key pair.

ssh-keygen

Copy the public key that was generated in the file id_rsa.pub to the clipboard

pbcopy < ~/.ssh/id_rsa.pub

Add the public key to BitBucket

Navigate to your admin section of your BitBucket account (User Icon > Manage Account Link > SSH Keys list option)

At time of writing you would be at: https://bitbucket.org/account/user/<my-bitbucket-user-account>/ssh-keys/

Click add key and paste into the Key text area the text from the clipboard.

Give it a label so you can identify the key.

Create a sample swift project (OSX command line tool)

  • Open XCode
  • File > New > Project
  • Here we will choose a template OSX > Application > Command Line Tool
  • Next
  • Product Name: swift-sample
  • Language: Swift
  • Next
  • Choose a suitable location e.g. ~/dev/repos/swift/samples
  • Tick “Source Control:” checkbox Create Git repository on My Mac
  • You can also choose if you want the project added to an existing project or workspace
  • Add to: Don’t add to any project or workspace (i.e. a new workspace will be created for this project)
  • Click Create

A project will now open in a new workspace.

You can try out the app by clicking Product > Run (Command + R)

You should see “Hello, World!” in the console.

Create a Git Repo on BitBucket

  • In BitBucket in browser click Create
  • Name: swift-sample
  • Repository Type: Git
  • Check Access Level: This is a private repository (unless you want everyone to see your ramblings)
  • Language: Swift
  • Click Create Repository

This will present some info on how to clone your project and one of the links presented will have a url like:

git@bitbucket.org:smith9/swift-sample.git

Change the origin of your project in XCode to link to your Git Repo on BitBucket

  • Source Control > Working Copies > swift-sample > Configure swift-sample…
  • Click remotes
  • Click +
  • Click Add Remote
  • Name: origin
  • Address: git@bitbucket.org:smith9/swift-sample.git (this is the address from previous step)
  • Click Add Remote
  • Click Done

Your project’s local Git master repo is now connected to your BitBucket remote origin repo.

The local files will already have been committed to the local repo.

Change one of the files and try committing and pushing the files to BitBucket

  • Edit a file e.g. main.swift
  • Source Control > Commit…
  • Source Control > Push

You can now go to the BitBucket site and see the commit.

 

 

Advertisements

From → Apple, Uncategorized

6 Comments
  1. This is really good one, thanks for sharing knowledge

  2. Rick permalink

    This was really, really useful. Thanks!

  3. Thanks!

  4. I followed the instructions point by point and can’t get it to work. I keep getting authentication failed. I’ve tried every possible combination of passwords and configurations on the remote.

  5. Resolved using an HTTPS URI instead for the remote: https://bitbucket.org/username/repo.git

Trackbacks & Pingbacks

  1. Creating a Swift Project in XCode 6 and adding it to a git repo on BitBucket | iPhone Blog

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: