Changes between Initial Version and Version 1 of cs222p-2018-fall-git


Ignore:
Timestamp:
Sep 26, 2018, 1:32:33 PM (7 years ago)
Author:
Qiushi Bai
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • cs222p-2018-fall-git

    v1 v1  
     1Suppose the CS222P team 99 contains 2 members (Bob and Alice). We will see how they use Git to collaborate in the CS222P class.
     2
     3== Setting up Git:
     4
     5 1. Each student creates a github account, and shares his/her github username with the CS222P staff on this [https://docs.google.com/spreadsheets/d/1hI49H-dG-GV_EAd4yfqUkdAapZJ1a1vY5Uy46FN9rpg/edit#gid=1065497958 spreadsheet].
     6 1. The staff will send each of them an invitation to join the [https://github.com/UCI-Chenli-teaching UCI-chenli-teaching] organization. Both accept the invitation and are added to the organization.
     7 1. One team member, say Bob, needs to create a  '''private''' (default setting) repository called '''cs222p-fall18-team-99''' (naming format is "cs222p-fall-team-xx" where "x" is your assigned team number.) on Github.com within organization '''UCI-chenli-teaching'''.
     8 * 1) Go to [https://github.com/UCI-Chenli-teaching UCI-Chenli-teaching organization].
     9 * 2) Click the '''New''' button to create a repository.
     10[[Image(wiki:cs222p-2018-fall-project1-git:create-repo-button.png)]]
     11 * 3) Type in the name and choose '''private'''.
     12[[Image(wiki:cs222p-2018-fall-project1-git:create-repo-interface.png)]]
     13 1. Bob also needs to add the other member Alice to the repository as a collaborator (by following steps given [https://help.github.com/articles/inviting-collaborators-to-a-personal-repository/ here]).
     14
     15== Using Git:
     16
     17 1. On his local machine, Bob installs a Git client by following the instructions [https://git-scm.com/book/en/v2/Getting-Started-Installing-Git here].
     18 1. He then does the following:
     19
     20{{{
     21shell> mkdir mycs222p-projects
     22shell> cd mycs222p-projects
     23shell> git init
     24shell> echo "Cool project" > README.md          - creates a README file
     25shell> git status          - check the status of the repository
     26shell> git add README.md          - The file is initially untracked by Git. 'git add' moves it to staged.
     27shell> git status           - check the status of the repository after staging the file
     28shell> git commit -m "First Commit"          - The staged files are committed locally.
     29shell> git status          - check the status of the repository after committing the file
     30}}}
     31 3. The local repository now has to be linked to the remote repository. For that Bob does the following:
     32
     33{{{
     34shell> git remote add origin git@github.com:UCI-Chenli-teaching/cs222p-fall18-team-99.git
     35shell> git push -u origin master
     36}}}
     37 4. Bob now wants to start on project 1. He creates a new branch from the master branch for this task.
     38
     39{{{
     40shell> 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.
     41shell> 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.
     42shell> mkdir project1
     43shell> cd project1
     44shell> echo "#include <iostream> using namespace std; int main() { cout << "Hello, World!"; return 0; }" > hello.cpp
     45shell> git add hello.cpp
     46shell> git commit -m "added hello world"            - commits changes locally to the bob-feature1 branch
     47shell> git push --set-upstream origin bob-feature1            - creates a remote tracking branch for the local bob-feature1 branch
     48}}}
     49 5. 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:
     50
     51{{{
     52shell> mkdir gitclones
     53shell> cd gitclones
     54shell> git clone https://<Alice's username>@github.com/UCI-Chenli-teaching/cs222p-fall18-team-99.git             - brings the repository onto her local machine
     55shell> cd cs222p-fall18-team-99
     56shell> git checkout bob-feature1             - She is initially on master branch. This statement changes her branch bob-feature1 branch. She can now see project 1 code and does the required changes.
     57shell> cd project1
     58MODIFY THE FILE hello.cpp
     59shell> git add hello.cpp
     60shell> git status
     61shell> git config  user.email "alince@alice.com"
     62shell> git config  user.name "Alice Smith"
     63shell> git commit -m "minor changes"
     64shell> git push             - pushes the commit to bob-feature1 remote branch
     65}}}
     66 6. 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:
     67
     68{{{
     69shell> git branch        - to see which branch he is on. He sees he is on bob-feature1 branch.
     70shell> git pull             - pulls the latest code. Bob now sees the changes that Alice pushed.
     71}}}
     72
     737. 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 [https://www.youtube.com/watch?v=oFYyTZwMyAg video] to learn this process.
     74
     75Refer to following tutorials for more information:
     76 * https://try.github.io
     77 * https://product.hubspot.com/blog/git-and-github-tutorial-for-beginners