Git & BitBucket Tutorial
All your work in this class will be submitted via our shared private repository on BitBucket. You should at this point have received and accepted an invitation to collaborate on a shared repository named
cs442-spring12-yourusername, during which process you would have created a free account on BitBucket. Contact me pronto if you still need an invitation!
For the remainder of this tutorial we'll look at how John Doe student (username
jdoe on BitBucket) will carry out some typical version control tasks using the
git command line tool.
1. Cloning the repository
The following transcript demonstrates how John would clone his repository on the local machine:
$ git clone https://bitbucket.org/michaelee/cs442-spring12-jdoe.git Cloning into cs442-spring12-jdoe... Username: jdoe Password: ********* remote: Counting objects: 6, done. remote: Compressing objects: 100% (5/5), done. remote: Total 6 (delta 0), reused 0 (delta 0) Unpacking objects: 100% (6/6), done. $ ls cs442-spring12-jdoe/
Note that when prompted for his username and password, John types in his BitBucket account information.
2. Adding files and commiting to the local repository
After creating a new Xcode project in the git-controlled directory, John does the following to add and commit his files:
$ cd cs442-spring12-jdoe $ git status # On branch master # Untracked files: # (use "git add <file>..." to include in what will be committed) # # MyNewProject/ nothing added to commit but untracked files present (use "git add" to track) $ git add MyNewProject $ git config user.name "John Doe" $ git config user.email "email@example.com" $ git commit -m "Initial commit for MyNewProject" [master 453a4f8] Initial commit for MyNewProject 7 files changed, 416 insertions(+), 0 deletions(-) create mode 100644 MyNewProject/MyNewProject.xcodeproj/project.pbxproj create mode 100644 MyNewProject/MyNewProject/AppDelegate.h create mode 100644 MyNewProject/MyNewProject/AppDelegate.m create mode 100644 MyNewProject/MyNewProject/MyNewProject-Info.plist create mode 100644 MyNewProject/MyNewProject/MyNewProject-Prefix.pch create mode 100644 MyNewProject/MyNewProject/en.lproj/InfoPlist.strings create mode 100644 MyNewProject/MyNewProject/main.m $ git log commit 048c71c22f1d38b1a4c8cb73be55ce351fea641b Author: John Doe <firstname.lastname@example.org> Date: Wed Feb 15 22:01:34 2012 -0600 Initial commit for MyNewProject commit 3caa74862b8f17f356841bfa2d380a817f371ffe Author: Michael Lee <email@example.com> Date: Thu Jan 12 16:48:59 2012 -0600 Adding initial README commit 12cb858e8ecb869d9dc1489283741c9897a3b7f9 Author: Michael Lee <firstname.lastname@example.org> Date: Thu Jan 12 16:37:00 2012 -0600 Adding Xcode gitignore
Note John's use of
git config to set his name and e-mail, which will be used in commit log messages. This only needs to be performed once, after cloning the repository and before the first commit. Also note the use of
git status and
git log to check the state of the local repository.
3. Pushing commits to the shared repository
Finally, after working on the project for a while and making one or more commits, the following pushes all of John's work (in the master branch) to the remote repository:
$ git status # On branch master # Your branch is ahead of 'origin/master' by 1 commit. # nothing to commit (working directory clean) $ git push origin master Username: jdoe Password: ********* Counting objects: 14, done. Delta compression using up to 2 threads. Compressing objects: 100% (10/10), done. Writing objects: 100% (13/13), 4.90 KiB, done. Total 13 (delta 0), reused 0 (delta 0) remote: bb/acl: michaelee is allowed. accepted payload. To https://bitbucket.org/michaelee/cs442-spring12-jdoe.git 3caa748..048c71c master -> master