Lab 5: Dr. Tig’s Git Tutorial - Dalhousie...

23
CSCI 2132 Software Development Lab 5: Dr. Tig’s Git Tutorial Instructor: Vlado Keselj Slides copyright: Raphael Bronfman-Nadas Faculty of Computer Science Dalhousie University 11-Oct-2017 (5) CSCI 2132 1

Transcript of Lab 5: Dr. Tig’s Git Tutorial - Dalhousie...

CSCI 2132Software Development

Lab 5:

Dr. Tig’s Git Tutorial

Instructor: Vlado Keselj

Slides copyright: Raphael Bronfman-Nadas

Faculty of Computer Science

Dalhousie University

11-Oct-2017 (5) CSCI 2132 1

What is Git?

• Please follow the story of Dr. Tig . . .• Git is something called version control software, simliarto SVN• It lets you go back in time• It is kind of like Google docs, but more manageable• For some help installing git, you can checkhttp://web.cs.dal.ca/˜raphael/GetGit.

11-Oct-2017 (5) CSCI 2132 2

What is Git good for?

• Git is great for keeping track of changes. Most peopleuse it for programs, and some people for text documents.Lots of people use it for group work• Git is great when something was working, but not it isnot.• Git allows groups to all work on their own copy andcombining the changes later.• Git keeps your work organized over time.

11-Oct-2017 (5) CSCI 2132 3

What is GitHub?

When they are not taking over the world, GitHub is awebsite that hosts a bunch of git projects. Lots of opensource projects, or they host private projects as well. Thereis a student developer pack which comes with a bunch ofstuff, and is free for students and can be found here athttps://education.github.com/pack.

11-Oct-2017 (5) CSCI 2132 4

Task 1: Finding my Evil Plan

Part 1: Cloning

• First prepare a directory where you will do this lab. Forexample, on ‘bluenose’ you could create a directory named‘gitlab’ or ‘lab5’ in your course directory, and work there.• This lab will not be submitted as an assignment, but anassignment question will be related to it.• Now we can continue with the Cloning Task. . .

11-Oct-2017 (5) CSCI 2132 5

Continuing with Cloning Task. . .

• My evil plan is on GitHub, you need to get a copy first• A folder using git is called a git repository• It’s located here:https://github.com/DalCSS/GeekLabsGit.git• You need to clone it• All git commands are very similar in structure:git <A command word> <Arguments to thatword>• You need to use clone command:

git clone https://github.com/DalCSS/GeekLabsGit.git

11-Oct-2017 (5) CSCI 2132 6

If everything is working, you should now have a new folderwith the name GeekLabsGit. To go into the folder on thecommand line, write:

cd GeekLabsGit

• You can check the map and plan files.• Check the plan in the file plan.txt• Note: Record all parts of the evil plan somewhere, youwill need this for the assignment.

11-Oct-2017 (5) CSCI 2132 7

Part 2: History

• We have the most recent version, but we can go back intime.• Each point in the past is called a commit• Let us look at the history first• Our command for that is log• Use the command “git log” (You may need to press qto get out of the log.)• Make checkout of the commit before the last one andcheck the plan.

11-Oct-2017 (5) CSCI 2132 8

Part 3: Branches

• Dr. Tig’s minions must use branches, which he canapprove• Try git command branch with the option -a at the end• Use git command checkout to check out the minionbranch and find out the next part of the evil plan

11-Oct-2017 (5) CSCI 2132 9

Part 4: Diff

• Use git to show the difference between minon’s andDr. Tig’s version of Cryptex.txt• You can use log to find the last two commits and do diffon them• This should reveal the next part of the Evil Plan

11-Oct-2017 (5) CSCI 2132 10

Part 5: Branch diff

• Find out more changes made to Cryptex.txt bycomparing it with the master branch.• Experiment to do this. This should reveal the last part ofthe plan.

• This finished the first task of the tutorial.

11-Oct-2017 (5) CSCI 2132 11

Task 2: Making Your Own Plan

Part 1: Creating a Repository

• You can create your own evel plan.• Get out of the current directory (cd ..) and start a newgit project using the git command ‘init folderName’where you want git to create a folder with the namefolderName.• You need to tell git who you are. . .

11-Oct-2017 (5) CSCI 2132 12

Tell Git Which Editor You Use

• You should first set the editor that git uses by default.• If you are on Mac or Linux:

git config --global core.editor "emacs"

• If you are on Windows, you can use notepad++ (oneline):

git config --global core.editor"’C:/Program Files (x86)/Notepad++/notepad++.exe’

-multiInst -nosession"

• Otherwise the vi or vim editor will be used

11-Oct-2017 (5) CSCI 2132 13

Tell Git Who You Are

• Set up your name (quotation marks are important):

git config --global user.name "Your name here"

• Set up your email (all in one line):

git config --global user.email"[email protected]"

11-Oct-2017 (5) CSCI 2132 14

Part 2: Commit

• Create your first draft of you evil plan. . .• Try the git status command• Add the file using add command• Check the status again• Commit the changes• Try option -m with the commit command• Make several commits, remember to add file that youchanged

11-Oct-2017 (5) CSCI 2132 15

Part 3: Branches

• Use the command branch to create a branch• Make some changes and make commits in the branch

11-Oct-2017 (5) CSCI 2132 16

Part 4: Setup for things to come

• Make some changes to the “minion” branch, and returnto the master branch• Make changes in the master branch that are in the sameas the changes on the minion branch• Commit those changes and we are ready to exploremerging and merge conflicts

11-Oct-2017 (5) CSCI 2132 17

Part 5: Merge and merge conflicts

• Use status to make sure that everything is commited• Using the git command merge merge the changes in theminion branch to the master branch• You should get a report about a conflict• Edit the file to resolve the conflict and them to yourcommit

11-Oct-2017 (5) CSCI 2132 18

Optional Share

• You need to use an external repository to share your plan• A popular choice is GitHub• If you want, you can create a GitHub account to shareyour code• A GitHub account is free. This is not required for thecourse, but it is frequently recommended in job search tohave your GitHub account with samples of your code.• In GitHub page, click on ‘+’ in the right corner and add anew repository• Do not initialize it with a README• Take a note of your git repository

11-Oct-2017 (5) CSCI 2132 19

Uploading Your Project to GitHub Repository

• Indicate your remote repository with:git remote add origin 〈git repository you copied〉• Save the branches with:

git push -u origin mastergit push -u origin minion

• Check the repository online• Now you can clone to another computer• You can use git command push and pull:

push — to push to internet repositorypull — to pull changes to your local repository form

internet

11-Oct-2017 (5) CSCI 2132 20

The end

• These are the most important commands• You can explore graphical views on GitHub• Here are a few more interesting notes: • .gitignorefile lists files to ignore for commits• HEAD is shortcut for where you are• ˆ means one before; e.g.,git checkout HEADˆ with checkout one commit back• show is a useful to show information on many things• diff can take zero or one arguement (not only 2)• man git and git --help give helpful information

11-Oct-2017 (5) CSCI 2132 21

A guide to all commands used

git clone 〈URL〉git loggit checkoutgit branchgit diffgit initgit config 〈parameter name〉git add 〈Files〉git statusgit commitgit merge 〈branch name〉git remote add origin 〈URL〉git push

11-Oct-2017 (5) CSCI 2132 22

git pull

11-Oct-2017 (5) CSCI 2132 23