There are many tutorials on Git which explain things much better than I can, so I'll just link the materials and go over what you'll be using the most.
- Clone repo
- Switch branches
- Create branch
- Commit changes
- Push branch
Atlassian has some pretty good docs for learning git.
I recommend reading through everything, but I cherry-picked the most important stuff below:
A repository is the location for which the files for a project are stored. Think of it like a fancy folder.
Most programming projects, especially collaborative ones, use git repos for version control.
This is not just an iOS development thing! If you plan to work in software engineering, there is a 99.9% chance you will be dealing with git.
For each module, you'll be creating a fork of the module repo which will be associated with your account.
To fork, click on the "Fork" button on this module's Github page. It should be located between "Watch" and "Star".
In the Create a new fork page, you shouldn't need to change anything, but it should have the following configuration:
- Owner is your github account
- Repository name is identical to forking repo (
bootcamp-module-0
) - The option to copy the main branch only is checked.
After pressing the Create fork button, you should be redirected to your newly forked repo page.
Since repositories (like this) are hosted remotely on websites like Github, you need a way to copy the project over on to your device.
You could just download the source as a zip file, but you'll lose many of the powerful features that git offers.
This tutorial will focus on using git via the Xcode interface, but you should try out git via the command line first.
- Open the Xcode app and click
Clone Git Repository
- Enter the URL of the git repo. Refer to the image below to locate the URL. Note: Make sure to clone the SSH url, not the HTTPS url.
-
Select the folder you want to store the repo. You'll need this throughout the course so don't just put it in your downloads!
-
Xcode should now open up with the cloned repo. Or it'll crash. It's Xcode.
-
If Xcode doesn't open immediately, go to the folder you just cloned and right click on
GettingStarted.playground
, select Open With -> Xcode.
- Clone repo
cd [project destination path]
git clone [repo url]
When working on a large project or with others, you want to make your changes on a separate branch so that if something breaks, it doesn't ruin the whole project.
-
In the top-left corner of Xcode, click on the box symbol next to the folder.
You should now see a panel with a
Changes
tab and aRepositories
tab. -
Switch to the
Repositories
tab. You should see abootcamp-module-0
repo. -
If not selected already, click the dropdown arrow to reveal repo details.
-
You should now see a couple more menu options. Right/double click on the
Branches
item and selectNew Branch from...
-
Enter a name for the branch. We suggest
github_username-edits
(replacegithub_username
with your actual Github username) -
You should now be automatically switched to your newly created branch.
- Clone repo
- Switch branches
- Create branch
git pull origin
git checkout -b [branch name]
-
Click on the folder icon to go back to the project source. It should look a little different now. Notice the
GettingStarted
playground file. -
Click on
GettingStarted
if you're not already there. -
Read and follow the instructions in the file. Then come back here.
-
Click on
Integrate
in the top menu bar and selectCommit...
-
Stage all files by clicking
Stage All
-
Enter a meaningful commit message like
Update name
-
Before committing, make sure you're on the right branch. Do not make commits to
main
-
Once you're sure of your changes, click
Commit
- Clone repo
- Switch branches
- Create branch
- Commit changes
[Complete steps 1-3]
git add *
git commit -m "[your message]"
Note: This is a risky operation. Make sure you're on the right branch!
(The right branch is not main
)
-
Click on
Integrate
in the top menu bar and selectPush...
-
You should see a pop-up that says
Push local changes to:
along with the remote branch. -
Click
Push
. Hopefully, Xcode won't crash at this point.
- Clone repo
- Switch branches
- Create branch
- Commit changes
- Push branch
git push --set-upstream origin [branch name]
This is a very important concept that many companies in the real world enforce. Changes should be pushed on a seperate branch and merged into main.
Now you've learned how to pull, commit, and push your changes to a project.
But you're just making changes to your feature branch. What if you want to actually push your changes to the project as a whole?
A common way to merge changes is to open a pull request through Github so that others can review and approve your changes.
Then, once your changes are approved, they can be merged through Github's interface.
Later in the semester, you'll do this in a group project.
To submit your work, make the forked version of the repository public then share the link with your instructor. Under your repository name, click Settings.
If you cannot see the "Settings" tab, select the ... dropdown menu, then click Settings.
In the "Danger Zone" section, to the right of to "Change repository visibility", click Change visibility.
Select a visibility.