Suppose the CS122B team 999 contains 2 members (Bob and Alice). We will see how they use Git to collaborate in the CS122B class.

Setting up Git:

  1. Each student creates a github account, and shares his/her github username with the CS122B staff on this spreadsheet.
  2. The staff will send each of them an invitation to join the “UCI-chenli-teaching” organization. Both accept the invitation and are added to the organisation.
  3. Bob creates a repository called “cs122b-winter19-team-999” on under this organization. Make sure to make it “private” (default setting). The repository is initially empty.

Using Git:

  1. On his local machine, Bob installs a Git client by following the instructions here.
  2. He then does the following:
shell> mkdir mycs122b-projects
shell> cd mycs122b-projects
shell> git init
shell> echo "Cool project" >          - creates a README file
shell> git status          - check the status of the repository
shell> git add          - The file is initially untracked by Git. 'git add' moves it to staged.
shell> git status           - check the status of the repository after staging the file
shell> git commit -m "First Commit"          - The staged files are committed locally.
shell> git status          - check the status of the repository after committing the file
  1. The local repository now has to be linked to the remote repository. For that Bob does the following:
shell> git remote add origin 
shell> git push -u origin master
  1. Bob now wants to start on project 1. He creates a new branch from the master branch for this task.
shell> git branch            - This command is used to check which branch you are on and what branches are there in your repository. master should be highlighted as you are on master branch. 
shell> git checkout -b bob-feature1            - This command creates a new branch and copies all the code from the previous (i.e. master in our case) branch into the new branch. 
shell> mkdir project1 
shell> cd project1 
shell> echo "SELECT * FROM stars" > mysql-script.sql 
shell> git add mysql-script.sql 
shell> git commit -m "added mysql command"   - commits changes locally to bob-feature1 
shell> git push --set-upstream origin bob-feature1   - creates a remote tracking branch
  1. Alice wants to contribute too. First Bob needs to invite Alice as a contributor to this repository on the Github web site. Then she can see the repository. She does the following:
shell> mkdir gitclones 
shell> cd gitclones 
shell> git clone https://<Alice's username>             - brings the repository onto her local machine 
shell> cd cs122b-winter19-team-999 
shell> git checkout bob-feature1    - Change from the master branch to the branch bob-feature1 branch. 
shell> cd project1
MODIFY THE FILE add mysql-script.sql
shell> git add mysql-script.sql 
shell> git status
shell> git config ""
shell> git config "Alice Smith"
shell> git commit -m "minor changes" 
shell> git push             - pushes the commit to bob-feature1 remote branch
  1. Bob wants to continue coding. Before proceeding to modify any files, he needs to do 'git pull' so that the local branch pulls the latest code from the remote branch. In particular, Bob does:
shell> git branch        - to see which branch he is on. He sees he is on bob-feature1 branch. 
shell> git pull             - pulls the latest code. Bob now sees the changes that Alice pushed.
  1. Bob and Alice can also use github to create a pull request from the bob-feature1 branch to the master branch to do code reviews. Check this video to learn this process.
Last modified 18 months ago Last modified on Jan 16, 2019 10:19:42 PM