Skip to content

Instantly share code, notes, and snippets.

@keicoder
Created March 7, 2014 10:51
Show Gist options
  • Save keicoder/9409423 to your computer and use it in GitHub Desktop.
Save keicoder/9409423 to your computer and use it in GitHub Desktop.
objective-c : Source Control in Xcode 5
//Source Control in Xcode 5
//1. Git settings
//configure git with your name and email address so that your changes are tracked properly.
//open a Terminal window and enter the following commands:
//below commands will save your name and email to your local ~/.gitconfig file
git config --global user.name "YOUR NAME HERE"
git config --global user.email "EMAIL"
//To verify your changes, type in the following command in Terminal
git config –l //list all of the Git configuration options that are currently set.
git config –help //learn more about settings
//2. Adding Git to an existing project
//open the Terminal application, type cd with a space afterwards,
//then drag the project folder to the terminal window
ls -la //lists the items in the ExistingProject directory
//If the project were under git source control you’d see a hidden directory named .git
git init //If there isn’t one, initialize a Git repository for this project by typing
git status //see the current status of your working directory
//3. ignore many of the common types of files
//ignores many of the common types of files that you don’t typically want in your git repositories
//Open any text editor and add the followings lines to a new file
//and Save the file in your ExistingProject project directory and name it .gitignore
# Xcode
.DS_Store
*/build/*
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata
profile
*.moved-aside
DerivedData
.idea/
*.hmap
//type git status once again:
git status //this time there is no .DS_Store file as you specified it as one of the files to be ignored in .gitignore
//4. Command line commit
//add all the untracked files to the staging area
git add
git status //notice how everything in your project is in the staging area but not yet committed
git commit -m "Initial commit." //commit everything in the staging area along with the quoted message specified with the –m flag
git status //view the state of repository (default is master branch)
//Quit Xcode 5 and re-open ExistingProject. Select any item in the project and open the File Inspector
//now Xcode has a project with a Git repository initialized, a .gitignore file and the first commit.
//5. Committing changes in Xcode 5
//to commit the changes, right-click on the project file and select Source Control Commit
//to see commit logs, click and hold on the version editor button and select Log, Comparison or Blame
//to view your project history, from the main menu, select Source Control > History
//6. Adding the project to GitHub
//1. SSH setup
//GitHub uses a pair of keys — one public and one private — in order to communicate securely with your computer.
//First, find out if you already have an SSH keypair by typing the following commands in a Terminal window:
cd ~/.ssh
ls
//2. generate SSH key (if you don’t have)
//id_rsa.pub or id_dsa.pub
//If you see a file named id_rsa.pub or id_dsa.pub, you’ve already generated SSH keys
//If you don’t see either of those files, or you get a “No such file or directory” error,
//then type the following command in Terminal to generate a pair of SSH keys:
ssh-keygen -t rsa -C "YOUR EMAIL" //generate a pair of SSH keys
//add file name in termial. name it id_rsa
id_rsa
//then be prompted to enter a passphrase. this is optional but highly recommended to secure your keys.
//Once that’s done, your SSH keys are ready to be added to GitHub
//Your identification has been saved in id_rsa
//Your public key has been saved in id_rsa.pub
//3. Add SSH key to GitHub
//navigate to the .ssh directory in your home folder
//and open the id_rsa.pub file (or id_dsa.pub file if you have that one) in a text editor.
//Copy the contents of the file
//and go to your account settings on github.com
//select the SSH Keys option then click the Add SSH key button
//paste the contents you copied from the .pub file into the Key section and give it a title
//4. Create a new repository on GitHub
//GitHub home page, click on the New Repository button to create a new repository
//copy the SSH address from GitHub
//5. Pushing the changes to GitHub
//go back to Xcode and click the Source Control menu item.
//select the master branch and choose the Configure "your project"
//click the “Remotes” tab and then the “+” button
//type remote repository name, paste the SSH address which is copied from your GitHub repository
//select the Source Control menu item again in XCode and this time select the Push, click Push
//Go to your repository on github.com and see the results
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment