107
Git Git Version control with Git and GitHub 1

G i t€¦ · Git is a version control system : software that manages different versions of files 3 . 2. G i t Why is it useful? 1. Keep track of changes to files 2. Review and revert

  • Upload
    others

  • View
    1

  • Download
    0

Embed Size (px)

Citation preview

Page 1: G i t€¦ · Git is a version control system : software that manages different versions of files 3 . 2. G i t Why is it useful? 1. Keep track of changes to files 2. Review and revert

GitGitVersion control with Git and GitHub

1

Page 2: G i t€¦ · Git is a version control system : software that manages different versions of files 3 . 2. G i t Why is it useful? 1. Keep track of changes to files 2. Review and revert

IntroductionIntroductionEvan Hanson

Please interrupt to ask [email protected]

2.1

Page 3: G i t€¦ · Git is a version control system : software that manages different versions of files 3 . 2. G i t Why is it useful? 1. Keep track of changes to files 2. Review and revert

AdministriviaAdministriviaBathroomsWaterFire exitsMeeting point

2.2

Page 4: G i t€¦ · Git is a version control system : software that manages different versions of files 3 . 2. G i t Why is it useful? 1. Keep track of changes to files 2. Review and revert

AdministriviaAdministrivia

2.3

Page 5: G i t€¦ · Git is a version control system : software that manages different versions of files 3 . 2. G i t Why is it useful? 1. Keep track of changes to files 2. Review and revert

OverviewOverviewThese slides are online: Tutorial format (with some lecturing thrown in)Tutorial will be in phases (time permitting)1. Hands-on with GitHub and Atom2. Questions3. Discussion of GitHub workflows4. Hands-on with Git on the command line

http://cat-train.github.com/

2.4

Page 6: G i t€¦ · Git is a version control system : software that manages different versions of files 3 . 2. G i t Why is it useful? 1. Keep track of changes to files 2. Review and revert

OverviewOverviewGit is a powerful and potentially complex toolTwo goals for the day1. Cover core concepts and terminology2. Familiarise with a useful workflow

2.5

Page 7: G i t€¦ · Git is a version control system : software that manages different versions of files 3 . 2. G i t Why is it useful? 1. Keep track of changes to files 2. Review and revert

GitGit https://git-scm.org/

3.1

Page 8: G i t€¦ · Git is a version control system : software that manages different versions of files 3 . 2. G i t Why is it useful? 1. Keep track of changes to files 2. Review and revert

GitGitGit is a version control system:

software that manages different versions of files

3.2

Page 9: G i t€¦ · Git is a version control system : software that manages different versions of files 3 . 2. G i t Why is it useful? 1. Keep track of changes to files 2. Review and revert

GitGitWhy is it useful?

1. Keep track of changes to files2. Review and revert back to old versions3. Synchronise files between different locations4. Test changes without losing the original copy

3.3

Page 10: G i t€¦ · Git is a version control system : software that manages different versions of files 3 . 2. G i t Why is it useful? 1. Keep track of changes to files 2. Review and revert

GitGitWhy Git and not some other software?

1. Performance2. Flexibility3. Popularity

3.4

Page 11: G i t€¦ · Git is a version control system : software that manages different versions of files 3 . 2. G i t Why is it useful? 1. Keep track of changes to files 2. Review and revert

GitHubGitHub https://github.com/

4.1

Page 12: G i t€¦ · Git is a version control system : software that manages different versions of files 3 . 2. G i t Why is it useful? 1. Keep track of changes to files 2. Review and revert

GitHubGitHubGitHub is a hosting site for Git repositories

(with lots of extra features)

4.2

Page 13: G i t€¦ · Git is a version control system : software that manages different versions of files 3 . 2. G i t Why is it useful? 1. Keep track of changes to files 2. Review and revert

GitHubGitHubWhy is GitHub useful?

1. Free hosting for open source projects2. Interface for browsing and editing code3. Workflows for collaborating with others4. API for doing other fancy things

4.3

Page 14: G i t€¦ · Git is a version control system : software that manages different versions of files 3 . 2. G i t Why is it useful? 1. Keep track of changes to files 2. Review and revert

GitHubGitHubWhy GitHub and not some other software?

1. Popularity

4.4

Page 15: G i t€¦ · Git is a version control system : software that manages different versions of files 3 . 2. G i t Why is it useful? 1. Keep track of changes to files 2. Review and revert

AtomAtom https://atom.io/

5.1

Page 16: G i t€¦ · Git is a version control system : software that manages different versions of files 3 . 2. G i t Why is it useful? 1. Keep track of changes to files 2. Review and revert

AtomAtomAtom is a text editor

with some useful Git and GitHub-related features

5.2

Page 17: G i t€¦ · Git is a version control system : software that manages different versions of files 3 . 2. G i t Why is it useful? 1. Keep track of changes to files 2. Review and revert

Let's get startedLet's get startedUsing Git's primary workflow

6.1

Page 18: G i t€¦ · Git is a version control system : software that manages different versions of files 3 . 2. G i t Why is it useful? 1. Keep track of changes to files 2. Review and revert

OverviewOverview1. Create a project (on GitHub)2. Clone the project (onto your computer)3. Change some files4. Commit the changes5. Push the changes (to GitHub)

6.2

Page 19: G i t€¦ · Git is a version control system : software that manages different versions of files 3 . 2. G i t Why is it useful? 1. Keep track of changes to files 2. Review and revert

1. Create a project1. Create a projectInitialise a new "repository" from within GitHub

7.1

Page 20: G i t€¦ · Git is a version control system : software that manages different versions of files 3 . 2. G i t Why is it useful? 1. Keep track of changes to files 2. Review and revert

Create a projectCreate a projectGo to

If you have an account, log in

If you don't, create one

You may need to verify your email address

Click New repositoryOr navigate to

https://github.com/

https://github.com/new

7.2

Page 21: G i t€¦ · Git is a version control system : software that manages different versions of files 3 . 2. G i t Why is it useful? 1. Keep track of changes to files 2. Review and revert

Create a projectCreate a projectEnter repository name cs4hsCheck Initialize this repository with a READMEClick Create repository

7.3

Page 22: G i t€¦ · Git is a version control system : software that manages different versions of files 3 . 2. G i t Why is it useful? 1. Keep track of changes to files 2. Review and revert

Remote cs4hs repositoryRemote cs4hs repositoryExists on GitHub's servers

It is a "remote" repository

Publically accessibleAnyone can see it

Only you can modify it

7.4

Page 23: G i t€¦ · Git is a version control system : software that manages different versions of files 3 . 2. G i t Why is it useful? 1. Keep track of changes to files 2. Review and revert

2. "Clone" the project2. "Clone" the projectCopy the project so you can edit it

8.1

Page 24: G i t€¦ · Git is a version control system : software that manages different versions of files 3 . 2. G i t Why is it useful? 1. Keep track of changes to files 2. Review and revert

"Clone""Clone"Given the location of a repositoryMakes a copy of the projectStores it on your computerLinks the two copies

8.2

Page 25: G i t€¦ · Git is a version control system : software that manages different versions of files 3 . 2. G i t Why is it useful? 1. Keep track of changes to files 2. Review and revert

Clone the cs4hs repositoryClone the cs4hs repositoryOpen Atom

Close any "welcome" tabs

Change the theme (if desired)

8.3

Page 26: G i t€¦ · Git is a version control system : software that manages different versions of files 3 . 2. G i t Why is it useful? 1. Keep track of changes to files 2. Review and revert

Clone the cs4hs repositoryClone the cs4hs repositoryPress Control-Shift-P to enter a command

Type GitHub: Clone and press Enter

Choose file locationsClone from: your GitHub repository URL

To directory: wherever (but remember where!)

8.4

Page 27: G i t€¦ · Git is a version control system : software that manages different versions of files 3 . 2. G i t Why is it useful? 1. Keep track of changes to files 2. Review and revert

Local cs4hs repositoryLocal cs4hs repositoryExists on your computer

It is a "local" repository

Files and folders behave as usualLinked to the version on GitHub

8.5

Page 28: G i t€¦ · Git is a version control system : software that manages different versions of files 3 . 2. G i t Why is it useful? 1. Keep track of changes to files 2. Review and revert

3. Change some files3. Change some filesNow you can make changes to your local copy

9.1

Page 29: G i t€¦ · Git is a version control system : software that manages different versions of files 3 . 2. G i t Why is it useful? 1. Keep track of changes to files 2. Review and revert

Edit the READMEEdit the READMEEdit file "README.md"

Save with Control-S (or from the File menu)

# cs4hs

## Test project

This is a project used to experiment with Git and GitHub.

9.2

Page 30: G i t€¦ · Git is a version control system : software that manages different versions of files 3 . 2. G i t Why is it useful? 1. Keep track of changes to files 2. Review and revert

Add a Python programAdd a Python programEnter Control-Shift-P and Add FileEnter the path for the new file: hello.py

Remember to save with Control-S

print("Dear world,")

print("")

print("Hello!")

print("")

print("Sincerely, Evan")

9.3

Page 31: G i t€¦ · Git is a version control system : software that manages different versions of files 3 . 2. G i t Why is it useful? 1. Keep track of changes to files 2. Review and revert

Sidenote: the ".git" folderSidenote: the ".git" folderThe ".git" folder contains Git's data filesThey can be edited but not saved in your repository

9.4

Page 32: G i t€¦ · Git is a version control system : software that manages different versions of files 3 . 2. G i t Why is it useful? 1. Keep track of changes to files 2. Review and revert

Local changesLocal changesYou now have:1. Some edits to a file2. An entirely new fileThese changes only exist locallyThey have not been "saved" to your repository yet!

9.5

Page 33: G i t€¦ · Git is a version control system : software that manages different versions of files 3 . 2. G i t Why is it useful? 1. Keep track of changes to files 2. Review and revert

3.1 Tell Git who you are3.1 Tell Git who you areIf you saw a red error message like this:

*** Please tell me who you are.

Run

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

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

to set your account's default identity.

Omit --global to set the identity only in this repository.

fatal: unable to auto-detect email address (got 'atomuser@WIN-VU7

10.1

Page 34: G i t€¦ · Git is a version control system : software that manages different versions of files 3 . 2. G i t Why is it useful? 1. Keep track of changes to files 2. Review and revert

Tell Git who you areTell Git who you areEdit file ".git/config"Add to the end of the file:

[user]

name = Your Name

email = [email protected]

10.2

Page 35: G i t€¦ · Git is a version control system : software that manages different versions of files 3 . 2. G i t Why is it useful? 1. Keep track of changes to files 2. Review and revert

4. "Commit" the changes4. "Commit" the changesSave your edits to a new version of the project

11.1

Page 36: G i t€¦ · Git is a version control system : software that manages different versions of files 3 . 2. G i t Why is it useful? 1. Keep track of changes to files 2. Review and revert

"Commit""Commit"Saving changes is a two-step process:1. Add them to the "staging area"

Tells Git to include the file in the next commit

2. "Commit" the changesTells Git to save a new version of the project

A "commit" is a versionIncludes a message and attribution information

11.2

Page 37: G i t€¦ · Git is a version control system : software that manages different versions of files 3 . 2. G i t Why is it useful? 1. Keep track of changes to files 2. Review and revert

Stage the edited fileStage the edited fileOpen the "Git" paneYour changes are currently "unstaged"Right-click and Stage "README.md"

11.3

Page 38: G i t€¦ · Git is a version control system : software that manages different versions of files 3 . 2. G i t Why is it useful? 1. Keep track of changes to files 2. Review and revert

Commit the edited fileCommit the edited fileEnter a Commit message: something descriptiveClick Commit to master

11.4

Page 39: G i t€¦ · Git is a version control system : software that manages different versions of files 3 . 2. G i t Why is it useful? 1. Keep track of changes to files 2. Review and revert

Stage and commit the new fileStage and commit the new fileUse the same process, this time for "hello.py"

11.5

Page 40: G i t€¦ · Git is a version control system : software that manages different versions of files 3 . 2. G i t Why is it useful? 1. Keep track of changes to files 2. Review and revert

Local commit historyLocal commit historyYou now have a series of changesThis is your project's "commit history"It tells you who changed what, how, and whenYou can "revert" to previous versions

11.6

Page 41: G i t€¦ · Git is a version control system : software that manages different versions of files 3 . 2. G i t Why is it useful? 1. Keep track of changes to files 2. Review and revert

5. "Push" the changes5. "Push" the changesNow you can publish these new commits on GitHub

12.1

Page 42: G i t€¦ · Git is a version control system : software that manages different versions of files 3 . 2. G i t Why is it useful? 1. Keep track of changes to files 2. Review and revert

Log in to GitHubLog in to GitHubEdit file ".git/config"Add your username to the cloned URL

[remote "origin"]

url = https://<username>@github.com/<username>/cs4hs.git

12.2

Page 43: G i t€¦ · Git is a version control system : software that manages different versions of files 3 . 2. G i t Why is it useful? 1. Keep track of changes to files 2. Review and revert

Push your commitsPush your commitsOpen the "Git" paneClick Push 2

Enter your password

Check Remember

Visit GitHub to view your published changes

12.3

Page 44: G i t€¦ · Git is a version control system : software that manages different versions of files 3 . 2. G i t Why is it useful? 1. Keep track of changes to files 2. Review and revert

ReviewReview1. Created a project (on GitHub)2. Cloned the project (onto your computer)3. Changed some files4. Committed the changes5. Pushed the changes (to GitHub)

13

Page 45: G i t€¦ · Git is a version control system : software that manages different versions of files 3 . 2. G i t Why is it useful? 1. Keep track of changes to files 2. Review and revert

Next StepsNext StepsReviewing and modifying commits

14

Page 46: G i t€¦ · Git is a version control system : software that manages different versions of files 3 . 2. G i t Why is it useful? 1. Keep track of changes to files 2. Review and revert

Reviewing changesReviewing changesYour project now has a "history" you can review

15.1

Page 47: G i t€¦ · Git is a version control system : software that manages different versions of files 3 . 2. G i t Why is it useful? 1. Keep track of changes to files 2. Review and revert

Your project's historyYour project's historyA series of commitsEvery commit has:1. A message2. An author3. A date4. A set of changes5. A "parent" commit6. A unique ID

This is also known as its "hash" or "SHA1"15.2

Page 48: G i t€¦ · Git is a version control system : software that manages different versions of files 3 . 2. G i t Why is it useful? 1. Keep track of changes to files 2. Review and revert

Fix-upsFix-upsWhat to do when you've made a mistake?

16.1

Page 49: G i t€¦ · Git is a version control system : software that manages different versions of files 3 . 2. G i t Why is it useful? 1. Keep track of changes to files 2. Review and revert

Undo a commitUndo a commitOpen the "Git" paneClick Undo on the most recent commit

The commit is deleted

Its changes are moved back into the staging area

Its message is preserved

16.2

Page 50: G i t€¦ · Git is a version control system : software that manages different versions of files 3 . 2. G i t Why is it useful? 1. Keep track of changes to files 2. Review and revert

Fix a commitFix a commitEdit "hello.py" and add two lines at the end

Save the fileThe new changes are now unstaged

print("Dear world,")

print("")

print("Hello!")

print("")

print("Sincerely, Evan")

print("")

print("PS. I'm learning Git")

16.3

Page 51: G i t€¦ · Git is a version control system : software that manages different versions of files 3 . 2. G i t Why is it useful? 1. Keep track of changes to files 2. Review and revert

Fix a commitFix a commitStage the new changesCommit the result

You have just replaced the old commit with a new one

16.4

Page 52: G i t€¦ · Git is a version control system : software that manages different versions of files 3 . 2. G i t Why is it useful? 1. Keep track of changes to files 2. Review and revert

Push the commitPush the commitHover over the button you used to push

What does it say now?

16.5

Page 53: G i t€¦ · Git is a version control system : software that manages different versions of files 3 . 2. G i t Why is it useful? 1. Keep track of changes to files 2. Review and revert

Push the commitPush the commitTo push these commits you must "force push"Right-Click and choose Force Push

This overwrites data on the remote repository!

16.6

Page 54: G i t€¦ · Git is a version control system : software that manages different versions of files 3 . 2. G i t Why is it useful? 1. Keep track of changes to files 2. Review and revert

BranchesBranchesIsolating and sharing specific sets of changes

17.1

Page 55: G i t€¦ · Git is a version control system : software that manages different versions of files 3 . 2. G i t Why is it useful? 1. Keep track of changes to files 2. Review and revert

BranchesBranchesEach "branch" indicates a separate versionMultiple branches in a single repositoryLet you work without interfering with othersEventually combined or "merged"The default branch is called "master"

17.2

Page 56: G i t€¦ · Git is a version control system : software that manages different versions of files 3 . 2. G i t Why is it useful? 1. Keep track of changes to files 2. Review and revert

OverviewOverview1. Create a new branch2. Commit to the branch3. Push the branch (to GitHub)4. Create a pull request (on GitHub)5. Accept the pull request (on GitHub)

17.3

Page 57: G i t€¦ · Git is a version control system : software that manages different versions of files 3 . 2. G i t Why is it useful? 1. Keep track of changes to files 2. Review and revert

1. Create a new branch1. Create a new branchStarts a new set of changes

18.1

Page 58: G i t€¦ · Git is a version control system : software that manages different versions of files 3 . 2. G i t Why is it useful? 1. Keep track of changes to files 2. Review and revert

Create a branchCreate a branchOpen the "Git" paneClick master

Click New Branch

Type feature

Click New Branch (again)

You have a new "feature" branch

18.2

Page 59: G i t€¦ · Git is a version control system : software that manages different versions of files 3 . 2. G i t Why is it useful? 1. Keep track of changes to files 2. Review and revert

2. Commit to the branch2. Commit to the branchNew commits are added to the active branch

19.1

Page 60: G i t€¦ · Git is a version control system : software that manages different versions of files 3 . 2. G i t Why is it useful? 1. Keep track of changes to files 2. Review and revert

Create a new commitCreate a new commitEdit the file "README.md"

Save and commit the change as usual

# cs4hs

## Test project

This is a project used to experiment with Git and GitHub.

This is some information about the project.

19.2

Page 61: G i t€¦ · Git is a version control system : software that manages different versions of files 3 . 2. G i t Why is it useful? 1. Keep track of changes to files 2. Review and revert

Isolated changesIsolated changesClick feature to open the branch picker

Click master to switch branches

README.md has changed backThe edit has been made to the feature branch

The master branch remains unchanged

19.3

Page 62: G i t€¦ · Git is a version control system : software that manages different versions of files 3 . 2. G i t Why is it useful? 1. Keep track of changes to files 2. Review and revert

3. Push the branch3. Push the branchSend the new branch to GitHub

20.1

Page 63: G i t€¦ · Git is a version control system : software that manages different versions of files 3 . 2. G i t Why is it useful? 1. Keep track of changes to files 2. Review and revert

Push the branchPush the branchOpen the "Git" paneSwitch back to featureClick PublishVisit your project on GitHub

The feature branch has been pushed

20.2

Page 64: G i t€¦ · Git is a version control system : software that manages different versions of files 3 . 2. G i t Why is it useful? 1. Keep track of changes to files 2. Review and revert

4. Create a pull request4. Create a pull requestRequest your branch to be "merged"

21.1

Page 65: G i t€¦ · Git is a version control system : software that manages different versions of files 3 . 2. G i t Why is it useful? 1. Keep track of changes to files 2. Review and revert

Request a mergeRequest a mergeClick Compare & pull requestEnter some informationClick Create pull request

21.2

Page 66: G i t€¦ · Git is a version control system : software that manages different versions of files 3 . 2. G i t Why is it useful? 1. Keep track of changes to files 2. Review and revert

5. Accept the pull request5. Accept the pull requestMerge the "feature" branch into "master"

22.1

Page 67: G i t€¦ · Git is a version control system : software that manages different versions of files 3 . 2. G i t Why is it useful? 1. Keep track of changes to files 2. Review and revert

Merge the branchMerge the branchMake sure you're happy with the changes!Click Merge pull request

Add any information you'd like to include

Click Confirm merge

Click Delete branchRemoves it from the remote repository

22.2

Page 68: G i t€¦ · Git is a version control system : software that manages different versions of files 3 . 2. G i t Why is it useful? 1. Keep track of changes to files 2. Review and revert

Review the new commitsReview the new commitsThe two branches have been combinedThere are two new commits:1. Your own2. A "merge commit"The combination happened on GitHub

GitHub is the remote repository

Your local repository is now out of date

22.3

Page 69: G i t€¦ · Git is a version control system : software that manages different versions of files 3 . 2. G i t Why is it useful? 1. Keep track of changes to files 2. Review and revert

Update your local repoUpdate your local repoBack in Atom, open the "Git" paneOpen the branch picker

Switch back to master

Click FetchClick Pull 2

22.4

Page 70: G i t€¦ · Git is a version control system : software that manages different versions of files 3 . 2. G i t Why is it useful? 1. Keep track of changes to files 2. Review and revert

Update your local repoUpdate your local repoThe two new commits are pulled from GitHubYou are back up to date with "origin"

22.5

Page 71: G i t€¦ · Git is a version control system : software that manages different versions of files 3 . 2. G i t Why is it useful? 1. Keep track of changes to files 2. Review and revert

ReviewReview1. Created a new branch2. Committed to the branch3. Pushed the branch (to GitHub)4. Created a pull request (on GitHub)5. Accepted the pull request (on GitHub)

23

Page 72: G i t€¦ · Git is a version control system : software that manages different versions of files 3 . 2. G i t Why is it useful? 1. Keep track of changes to files 2. Review and revert

Merge ConflictsMerge ConflictsWhen two branches can't be combined safely

24.1

Page 73: G i t€¦ · Git is a version control system : software that manages different versions of files 3 . 2. G i t Why is it useful? 1. Keep track of changes to files 2. Review and revert

OverviewOverview1. Create two incompatible commits

One locallyOne on GitHub

2. Pull the remote change (from GitHub)3. Resolve the resulting conflict

24.2

Page 74: G i t€¦ · Git is a version control system : software that manages different versions of files 3 . 2. G i t Why is it useful? 1. Keep track of changes to files 2. Review and revert

1. Create two commits1. Create two commitsChanging the same line but with different content

25.1

Page 75: G i t€¦ · Git is a version control system : software that manages different versions of files 3 . 2. G i t Why is it useful? 1. Keep track of changes to files 2. Review and revert

Edit a file locallyEdit a file locallyOpen "README.md" and change the last line

Make it read "important information"Commit the result

# cs4hs

## Test project

This is a project used to experiment with Git and GitHub.

This is some important information about the project.

25.2

Page 76: G i t€¦ · Git is a version control system : software that manages different versions of files 3 . 2. G i t Why is it useful? 1. Keep track of changes to files 2. Review and revert

Edit a file remotelyEdit a file remotelyVisit your repository on GitHubClick the pencil icon on README.md

Make it read "unimportant information"Enter a commit messageClick Commit changes

# cs4hs

## Test project

This is a project used to experiment with Git and GitHub.

This is some unimportant information about the project.

25.3

Page 77: G i t€¦ · Git is a version control system : software that manages different versions of files 3 . 2. G i t Why is it useful? 1. Keep track of changes to files 2. Review and revert

2. Pull the remote change2. Pull the remote changeTry (and fail) to combine the two branches

26.1

Page 78: G i t€¦ · Git is a version control system : software that manages different versions of files 3 . 2. G i t Why is it useful? 1. Keep track of changes to files 2. Review and revert

Fetch changesFetch changesRight-click the Push 1 buttonClick Fetch

This retrieves the new commits

Click Pull 1This attempts to merge the changes

You should hit Merge conflicts

26.2

Page 79: G i t€¦ · Git is a version control system : software that manages different versions of files 3 . 2. G i t Why is it useful? 1. Keep track of changes to files 2. Review and revert

3. Resolve the conflict3. Resolve the conflictIndicate how the two changes should be combined

27.1

Page 80: G i t€¦ · Git is a version control system : software that manages different versions of files 3 . 2. G i t Why is it useful? 1. Keep track of changes to files 2. Review and revert

Pick a sidePick a sideThe two different versions are colouredEdit the highlighted region to be "correct"

Remember to save the file when finished

# cs4hs

## Test project

This is a project used to experiment with Git and GitHub.

This is some potentially important information about the project.

27.2

Page 81: G i t€¦ · Git is a version control system : software that manages different versions of files 3 . 2. G i t Why is it useful? 1. Keep track of changes to files 2. Review and revert

Commit the resultCommit the resultStage the fileClick Commit to masterThe conflict is resolved locally

27.3

Page 82: G i t€¦ · Git is a version control system : software that manages different versions of files 3 . 2. G i t Why is it useful? 1. Keep track of changes to files 2. Review and revert

Share the resultShare the resultWe still need to push the resolutionClick Push 2Now everything is back in sync

27.4

Page 83: G i t€¦ · Git is a version control system : software that manages different versions of files 3 . 2. G i t Why is it useful? 1. Keep track of changes to files 2. Review and revert

ReviewReview1. Created two incompatible commits2. Pulled to combine the two

Encountered a merge conflict3. Resolved the conflict

28

Page 84: G i t€¦ · Git is a version control system : software that manages different versions of files 3 . 2. G i t Why is it useful? 1. Keep track of changes to files 2. Review and revert

Questions?Questions?

29

Page 85: G i t€¦ · Git is a version control system : software that manages different versions of files 3 . 2. G i t Why is it useful? 1. Keep track of changes to files 2. Review and revert

GitHub WorkflowsGitHub WorkflowsA few helpful tips for working with GitLab

30

Page 86: G i t€¦ · Git is a version control system : software that manages different versions of files 3 . 2. G i t Why is it useful? 1. Keep track of changes to files 2. Review and revert

ForkingForkingContributing to a project that isn't yours

31.1

Page 87: G i t€¦ · Git is a version control system : software that manages different versions of files 3 . 2. G i t Why is it useful? 1. Keep track of changes to files 2. Review and revert

ForksForksA "fork" is a copy of a repo on GitHub

Copies from one user account to another

Think of it like a "remote clone"

31.2

Page 88: G i t€¦ · Git is a version control system : software that manages different versions of files 3 . 2. G i t Why is it useful? 1. Keep track of changes to files 2. Review and revert

ForksForksThe result is a repo you control

You clone your forked copy

You push commits

Pull request comes from your fork

31.3

Page 89: G i t€¦ · Git is a version control system : software that manages different versions of files 3 . 2. G i t Why is it useful? 1. Keep track of changes to files 2. Review and revert

Let's try itLet's try itNavigate to my cs4hs repository

Click forkhttps://github.com/cat-train1/cs4hs

31.4

Page 90: G i t€¦ · Git is a version control system : software that manages different versions of files 3 . 2. G i t Why is it useful? 1. Keep track of changes to files 2. Review and revert

Clone your forkClone your forkIn Atom use Control-Shift-P

Choose GitHub: Clone

Enter the fork's URL including your usernameClick Clone

31.5

Page 91: G i t€¦ · Git is a version control system : software that manages different versions of files 3 . 2. G i t Why is it useful? 1. Keep track of changes to files 2. Review and revert

Make some changesMake some changesUse the standard workflow:1. Edit2. Stage3. Commit4. PushVisit your project on GitHub

31.6

Page 92: G i t€¦ · Git is a version control system : software that manages different versions of files 3 . 2. G i t Why is it useful? 1. Keep track of changes to files 2. Review and revert

Open a pull requestOpen a pull requestClick New pull requestClick Create pull request

This request will be in my repo

31.7

Page 93: G i t€¦ · Git is a version control system : software that manages different versions of files 3 . 2. G i t Why is it useful? 1. Keep track of changes to files 2. Review and revert

Git CultureGit CultureSome keywords to help navigate the landscape

32.1

Page 94: G i t€¦ · Git is a version control system : software that manages different versions of files 3 . 2. G i t Why is it useful? 1. Keep track of changes to files 2. Review and revert

Git KeywordsGit KeywordsSquash: Combining many commits into oneRebase: Alternative to mergingFeature: Branch dedicated to specific featureHotfix: Branch dedicated to a single bugCI: Testing new commits automaticallyOthers?

32.2

Page 95: G i t€¦ · Git is a version control system : software that manages different versions of files 3 . 2. G i t Why is it useful? 1. Keep track of changes to files 2. Review and revert

Command LineCommand LineUsing the Git program from the terminal

33.1

Page 96: G i t€¦ · Git is a version control system : software that manages different versions of files 3 . 2. G i t Why is it useful? 1. Keep track of changes to files 2. Review and revert

Open a TerminalOpen a TerminalThis depends on your Operating System

Windows: Git Bash

macOS: Terminal

Linux: Terminal

33.2

Page 97: G i t€¦ · Git is a version control system : software that manages different versions of files 3 . 2. G i t Why is it useful? 1. Keep track of changes to files 2. Review and revert

Using the TerminalUsing the TerminalQuick command line how-to

33.3

Page 98: G i t€¦ · Git is a version control system : software that manages different versions of files 3 . 2. G i t Why is it useful? 1. Keep track of changes to files 2. Review and revert

The Git CommandThe Git CommandThe git command (lower case) runs GitEnter git --version to see whether it works

33.4

Page 99: G i t€¦ · Git is a version control system : software that manages different versions of files 3 . 2. G i t Why is it useful? 1. Keep track of changes to files 2. Review and revert

Configuring GitConfiguring Gitgit config core.editor "atom --wait"

git config user.name "Evan Hanson"

git config user.email

"[email protected]"

33.5

Page 100: G i t€¦ · Git is a version control system : software that manages different versions of files 3 . 2. G i t Why is it useful? 1. Keep track of changes to files 2. Review and revert

Cloning a projectCloning a projectgit clone <url>

cd cs4hs

git status

33.6

Page 101: G i t€¦ · Git is a version control system : software that manages different versions of files 3 . 2. G i t Why is it useful? 1. Keep track of changes to files 2. Review and revert

Making commitsMaking commitsatom README.md

git status

git add README.md

git commit -m "message goes here"

33.7

Page 102: G i t€¦ · Git is a version control system : software that manages different versions of files 3 . 2. G i t Why is it useful? 1. Keep track of changes to files 2. Review and revert

Reviewing historyReviewing historygit log

git show

git show <commit>

33.8

Page 103: G i t€¦ · Git is a version control system : software that manages different versions of files 3 . 2. G i t Why is it useful? 1. Keep track of changes to files 2. Review and revert

Fixing commitsFixing commitsgit reset <commit>

git reset --hard <commit>

git add

git commit

33.9

Page 104: G i t€¦ · Git is a version control system : software that manages different versions of files 3 . 2. G i t Why is it useful? 1. Keep track of changes to files 2. Review and revert

BranchingBranchinggit branch

git branch <name>

git checkout <name>

33.10

Page 105: G i t€¦ · Git is a version control system : software that manages different versions of files 3 . 2. G i t Why is it useful? 1. Keep track of changes to files 2. Review and revert

Questions?Questions?

34

Page 106: G i t€¦ · Git is a version control system : software that manages different versions of files 3 . 2. G i t Why is it useful? 1. Keep track of changes to files 2. Review and revert

Thanks!Thanks!Evan Hanson

Slides will be emailed outDon't hesitate to contact me!

[email protected]

35

Page 107: G i t€¦ · Git is a version control system : software that manages different versions of files 3 . 2. G i t Why is it useful? 1. Keep track of changes to files 2. Review and revert

36