However, since working with Xcode and Swift is new to most SAP developers, this little blog should give you an idea how to best set up Xcode for working with GitHub, especially if you are using the SAP Cloud Platform SDK for iOS.
Setting up .gitignore_global
With Git, you can create a so-called ‘ignore’ file which holds a list of files and filetypes that should not be tracked by version control. You can do this local, per project, in a
.gitignore file, or globally, for all projects, in a
.gitignore_global file. In the local file you would specify files to ignore for a specific project. In the global file, you would ignore files you wouldn’t track in any project. Since I want to ignore files for every project I will create, in this blog I focus on the
First, check whether you have a
.gitignore_global file in your home folder.
Open a terminal to your home folder
~ and type:
and check if you see the file
If it does not exist, type:
to create the file.
Open the file with your favourite text editor.
First, add the following general exclusions:
The first entry ignores any file ending at
~, which is a typical format for temporary or backup files
The second entry ignores all macOS’ Desktop Services Store files, which generally holds data such as position of icons, folder backgrounds, etc.
Then add the following Xcode exclusions:
## Build generated build/ DerivedData/ ## Various settings *.pbxuser !default.pbxuser *.mode1v3 !default.mode1v3 *.mode2v3 !default.mode2v3 *.perspectivev3 !default.perspectivev3 xcuserdata/
For obvious reasons you don’t want the build generated folders end up in source control. The others are personalised data such as Xcode UI preferences.
And lastly, but most importantly, add the following:
##SAP Cloud Platform SDK for iOS framework files SAP*.framework
This will ignore the SDK’s framework files being added to Git. As the EULA does not allow you to distribute the framework files, this is a good way to avoid them ending up erroneously in a (public) repository for anyone to find. In addition, it also saves you and your co-workers from committing and downloading an initial 275 MB of total framework file size…
If your system already contains a
.gitignore_global file, you can skip the next step. However, if you just created the
.gitignore_global file, you must run the following command:
git config --global core.excludesfile ~/.gitignore_global
This tells git to look for a global ignore file in your home folder. Now your local git is configured to use the global
.gitignore_global ignore file, and you can add a project to source control.
Add Xcode project to Source Control
Let’s say you have created an Xcode project using the SAP Cloud Platform SDK for iOS:
NB: In this example, I simply use one generated with the SDK Assistant, but if you’re serious about iOS / Swift software development, you should not use the generated project as a starting point.
From the top menu, select Source Control > Create Working Copy…
The following dialog appears:
Make sure your project is checked, and click the Create button. You now have created a local git repository.
If you now make a change to a file, for instance add a documenting comment to a function using ⌥⌘/ you’ll notice the little M appears next to the file:
This indicates the file is modified, and not yet committed to your repository. You can commit the file via the top menu Source Control > Commit… or by simply pressing ⌥⌘C.
However, this only lets you commit to your local repository.
Create remote repository
To connect to your GitHub repository, first make sure you have created an empty repository on GitHub:
Make sure you don’t initialise the repository with a README.md, .gitignore or license file yet (these can be added later)
Depending on how you prefer to connect with GitHub, copy either the HTTPS or SSH URL:
Add remote repository to Xcode
Go back to Xcode, and from the top menu, choose Source Control > your_project – master > Configure your_project…
In the dialog, click the + button and choose Add Remote…
In the dialog, leave the Name ‘origin’ and add the copied URL into the Address field:
After you click Add Remote, the remote repository is now listed:
Commit and push to remote repository
If you now commit any changes, you will notice you now have the possibility to push your changes to the remote repository as listed in the lower left corner:
Add a commit message, tick the Push to remote checkbox, and press the Commit <n> Files and Push button.
The files are now committed to the remote GitHub repository.
If you now open the repository in GitHub, you’ll see your project is successfully committed, without all personal preference files and, more importantly, without the SAP Cloud Platform SDK for iOS framework files!
If you have any other tips to share, please add them to the comments section. Happy coding!