Version 1 (modified by 7 years ago) ( diff ) | ,
---|
Suppose the CS222P team 99 contains 2 members (Bob and Alice). We will see how they use Git to collaborate in the CS222P class.
Setting up Git:
- Each student creates a github account, and shares his/her github username with the CS222P staff on this spreadsheet.
- 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 organization.
- 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.
- 1) Go to UCI-Chenli-teaching organization.
- 2) Click the New button to create a repository.
- 3) Type in the name and choose private.
- Bob also needs to add the other member Alice to the repository as a collaborator (by following steps given here).
Using Git:
- On his local machine, Bob installs a Git client by following the instructions here.
- He then does the following:
shell> mkdir mycs222p-projects shell> cd mycs222p-projects shell> git init shell> echo "Cool project" > README.md - creates a README file shell> git status - check the status of the repository shell> git add README.md - 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
- The local repository now has to be linked to the remote repository. For that Bob does the following:
shell> git remote add origin git@github.com:UCI-Chenli-teaching/cs222p-fall18-team-99.git shell> git push -u origin master
- 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 "#include <iostream> using namespace std; int main() { cout << "Hello, World!"; return 0; }" > hello.cpp shell> git add hello.cpp shell> git commit -m "added hello world" - commits changes locally to the bob-feature1 branch shell> git push --set-upstream origin bob-feature1 - creates a remote tracking branch for the local bob-feature1 branch
- 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>@github.com/UCI-Chenli-teaching/cs222p-fall18-team-99.git - brings the repository onto her local machine shell> cd cs222p-fall18-team-99 shell> 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. shell> cd project1 MODIFY THE FILE hello.cpp shell> git add hello.cpp shell> git status shell> git config user.email "alince@alice.com" shell> git config user.name "Alice Smith" shell> git commit -m "minor changes" shell> git push - pushes the commit to bob-feature1 remote branch
- 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.
- Bob and Alice can also use github to create a pull request from the
bob-feature1
branch to themaster
branch to do code reviews. Check this video to learn this process.
Refer to following tutorials for more information:
Attachments (2)
- create-repo-button.png (38.4 KB ) - added by 7 years ago.
- create-repo-interface.png (121.5 KB ) - added by 7 years ago.
Download all attachments as: .zip
Note:
See TracWiki
for help on using the wiki.