Lab 3: Version control and collaboration...What is version control? Distributed Snapshots Storage...

41
Introduction What is version control? Distributed Snapshots Storage landscape Using Git Gitting started... commit branch merge Merge conflicts Exploration Remote repositories Industrial workflow Final tips Lab 3: Version control and collaboration Comp Sci 1585 Data Structures Lab: Tools for Computer Scientists

Transcript of Lab 3: Version control and collaboration...What is version control? Distributed Snapshots Storage...

Page 1: Lab 3: Version control and collaboration...What is version control? Distributed Snapshots Storage landscape Using Git Gitting started... commit branch merge Merge con icts Exploration

Introduction

What is versioncontrol?

Distributed

Snapshots

Storagelandscape

Using Git

Gitting started...

commit

branch

merge

Merge conflicts

Exploration

Remoterepositories

Industrialworkflow

Final tips

Lab 3: Version control and collaboration

Comp Sci 1585Data Structures Lab:

Tools for Computer Scientists

Page 2: Lab 3: Version control and collaboration...What is version control? Distributed Snapshots Storage landscape Using Git Gitting started... commit branch merge Merge con icts Exploration

Introduction

What is versioncontrol?

Distributed

Snapshots

Storagelandscape

Using Git

Gitting started...

commit

branch

merge

Merge conflicts

Exploration

Remoterepositories

Industrialworkflow

Final tips

Outline

1 IntroductionWhat is version control?DistributedSnapshotsStorage landscape

2 Using GitGitting started...commitbranchmerge

Merge conflictsExplorationRemote repositoriesIndustrial workflowFinal tips

Page 3: Lab 3: Version control and collaboration...What is version control? Distributed Snapshots Storage landscape Using Git Gitting started... commit branch merge Merge con icts Exploration

Introduction

What is versioncontrol?

Distributed

Snapshots

Storagelandscape

Using Git

Gitting started...

commit

branch

merge

Merge conflicts

Exploration

Remoterepositories

Industrialworkflow

Final tips

Outline

1 IntroductionWhat is version control?DistributedSnapshotsStorage landscape

2 Using GitGitting started...commitbranchmerge

Merge conflictsExplorationRemote repositoriesIndustrial workflowFinal tips

Page 4: Lab 3: Version control and collaboration...What is version control? Distributed Snapshots Storage landscape Using Git Gitting started... commit branch merge Merge con icts Exploration

Introduction

What is versioncontrol?

Distributed

Snapshots

Storagelandscape

Using Git

Gitting started...

commit

branch

merge

Merge conflicts

Exploration

Remoterepositories

Industrialworkflow

Final tips

What is version control?

• Keeps track of changes to your code.

• You don’t have to worry about accidentally losing ordeleting code.

• You can experiment and reset to a known good state.

• Makes collaborating with others easier.

What is Git?

• Git is software - it is not GitHub, which is a website

• Distributed - everything is kept on your local machine.

• ‘Repository’ - a collection of code and history.

• ‘Commit’ - a chunk of saved changes.

Page 5: Lab 3: Version control and collaboration...What is version control? Distributed Snapshots Storage landscape Using Git Gitting started... commit branch merge Merge con icts Exploration

Introduction

What is versioncontrol?

Distributed

Snapshots

Storagelandscape

Using Git

Gitting started...

commit

branch

merge

Merge conflicts

Exploration

Remoterepositories

Industrialworkflow

Final tips

Outline

1 IntroductionWhat is version control?DistributedSnapshotsStorage landscape

2 Using GitGitting started...commitbranchmerge

Merge conflictsExplorationRemote repositoriesIndustrial workflowFinal tips

Page 6: Lab 3: Version control and collaboration...What is version control? Distributed Snapshots Storage landscape Using Git Gitting started... commit branch merge Merge con icts Exploration

Introduction

What is versioncontrol?

Distributed

Snapshots

Storagelandscape

Using Git

Gitting started...

commit

branch

merge

Merge conflicts

Exploration

Remoterepositories

Industrialworkflow

Final tips

Distributed version control

Page 7: Lab 3: Version control and collaboration...What is version control? Distributed Snapshots Storage landscape Using Git Gitting started... commit branch merge Merge con icts Exploration

Introduction

What is versioncontrol?

Distributed

Snapshots

Storagelandscape

Using Git

Gitting started...

commit

branch

merge

Merge conflicts

Exploration

Remoterepositories

Industrialworkflow

Final tips

Outline

1 IntroductionWhat is version control?DistributedSnapshotsStorage landscape

2 Using GitGitting started...commitbranchmerge

Merge conflictsExplorationRemote repositoriesIndustrial workflowFinal tips

Page 8: Lab 3: Version control and collaboration...What is version control? Distributed Snapshots Storage landscape Using Git Gitting started... commit branch merge Merge con icts Exploration

Introduction

What is versioncontrol?

Distributed

Snapshots

Storagelandscape

Using Git

Gitting started...

commit

branch

merge

Merge conflicts

Exploration

Remoterepositories

Industrialworkflow

Final tips

Snapshots (commits) include all files

Page 9: Lab 3: Version control and collaboration...What is version control? Distributed Snapshots Storage landscape Using Git Gitting started... commit branch merge Merge con icts Exploration

Introduction

What is versioncontrol?

Distributed

Snapshots

Storagelandscape

Using Git

Gitting started...

commit

branch

merge

Merge conflicts

Exploration

Remoterepositories

Industrialworkflow

Final tips

Outline

1 IntroductionWhat is version control?DistributedSnapshotsStorage landscape

2 Using GitGitting started...commitbranchmerge

Merge conflictsExplorationRemote repositoriesIndustrial workflowFinal tips

Page 10: Lab 3: Version control and collaboration...What is version control? Distributed Snapshots Storage landscape Using Git Gitting started... commit branch merge Merge con icts Exploration

Introduction

What is versioncontrol?

Distributed

Snapshots

Storagelandscape

Using Git

Gitting started...

commit

branch

merge

Merge conflicts

Exploration

Remoterepositories

Industrialworkflow

Final tips

Three places where edits exist

Page 11: Lab 3: Version control and collaboration...What is version control? Distributed Snapshots Storage landscape Using Git Gitting started... commit branch merge Merge con icts Exploration

Introduction

What is versioncontrol?

Distributed

Snapshots

Storagelandscape

Using Git

Gitting started...

commit

branch

merge

Merge conflicts

Exploration

Remoterepositories

Industrialworkflow

Final tips

Outline

1 IntroductionWhat is version control?DistributedSnapshotsStorage landscape

2 Using GitGitting started...commitbranchmerge

Merge conflictsExplorationRemote repositoriesIndustrial workflowFinal tips

Page 12: Lab 3: Version control and collaboration...What is version control? Distributed Snapshots Storage landscape Using Git Gitting started... commit branch merge Merge con icts Exploration

Introduction

What is versioncontrol?

Distributed

Snapshots

Storagelandscape

Using Git

Gitting started...

commit

branch

merge

Merge conflicts

Exploration

Remoterepositories

Industrialworkflow

Final tips

Outline

1 IntroductionWhat is version control?DistributedSnapshotsStorage landscape

2 Using GitGitting started...commitbranchmerge

Merge conflictsExplorationRemote repositoriesIndustrial workflowFinal tips

Page 13: Lab 3: Version control and collaboration...What is version control? Distributed Snapshots Storage landscape Using Git Gitting started... commit branch merge Merge con icts Exploration

Introduction

What is versioncontrol?

Distributed

Snapshots

Storagelandscape

Using Git

Gitting started...

commit

branch

merge

Merge conflicts

Exploration

Remoterepositories

Industrialworkflow

Final tips

Gitting Started...

• $ git init Makes a new empty git repository.

• $ git add <FILENAME> Adds changes in FILENAME tothe next commit.

• $ git status Shows the status of the repository.

• $ git config --global user.name "<YOUR FULL NAME>"

• $ git config --global user.email <EMAIL>

• $ git config --global core.editor vim

Page 14: Lab 3: Version control and collaboration...What is version control? Distributed Snapshots Storage landscape Using Git Gitting started... commit branch merge Merge con icts Exploration

Introduction

What is versioncontrol?

Distributed

Snapshots

Storagelandscape

Using Git

Gitting started...

commit

branch

merge

Merge conflicts

Exploration

Remoterepositories

Industrialworkflow

Final tips

Outline

1 IntroductionWhat is version control?DistributedSnapshotsStorage landscape

2 Using GitGitting started...commitbranchmerge

Merge conflictsExplorationRemote repositoriesIndustrial workflowFinal tips

Page 15: Lab 3: Version control and collaboration...What is version control? Distributed Snapshots Storage landscape Using Git Gitting started... commit branch merge Merge con icts Exploration

Introduction

What is versioncontrol?

Distributed

Snapshots

Storagelandscape

Using Git

Gitting started...

commit

branch

merge

Merge conflicts

Exploration

Remoterepositories

Industrialworkflow

Final tips

Committing

$ git commit -m ‘‘a’’

amaster

Page 16: Lab 3: Version control and collaboration...What is version control? Distributed Snapshots Storage landscape Using Git Gitting started... commit branch merge Merge con icts Exploration

Introduction

What is versioncontrol?

Distributed

Snapshots

Storagelandscape

Using Git

Gitting started...

commit

branch

merge

Merge conflicts

Exploration

Remoterepositories

Industrialworkflow

Final tips

Committing

$ git commit -m ‘‘b’’

a

bmaster

Page 17: Lab 3: Version control and collaboration...What is version control? Distributed Snapshots Storage landscape Using Git Gitting started... commit branch merge Merge con icts Exploration

Introduction

What is versioncontrol?

Distributed

Snapshots

Storagelandscape

Using Git

Gitting started...

commit

branch

merge

Merge conflicts

Exploration

Remoterepositories

Industrialworkflow

Final tips

Committing

$ git commit -m ‘‘c’’

a

b

cmaster

Page 18: Lab 3: Version control and collaboration...What is version control? Distributed Snapshots Storage landscape Using Git Gitting started... commit branch merge Merge con icts Exploration

Introduction

What is versioncontrol?

Distributed

Snapshots

Storagelandscape

Using Git

Gitting started...

commit

branch

merge

Merge conflicts

Exploration

Remoterepositories

Industrialworkflow

Final tips

Outline

1 IntroductionWhat is version control?DistributedSnapshotsStorage landscape

2 Using GitGitting started...commitbranchmerge

Merge conflictsExplorationRemote repositoriesIndustrial workflowFinal tips

Page 19: Lab 3: Version control and collaboration...What is version control? Distributed Snapshots Storage landscape Using Git Gitting started... commit branch merge Merge con icts Exploration

Introduction

What is versioncontrol?

Distributed

Snapshots

Storagelandscape

Using Git

Gitting started...

commit

branch

merge

Merge conflicts

Exploration

Remoterepositories

Industrialworkflow

Final tips

Branching

$ git checkout -b new-branch

a

b

c

master

new-branch

Page 20: Lab 3: Version control and collaboration...What is version control? Distributed Snapshots Storage landscape Using Git Gitting started... commit branch merge Merge con icts Exploration

Introduction

What is versioncontrol?

Distributed

Snapshots

Storagelandscape

Using Git

Gitting started...

commit

branch

merge

Merge conflicts

Exploration

Remoterepositories

Industrialworkflow

Final tips

Branching

$ git commit -m ‘‘d’’

a

b

c

d

master

new-branch

Page 21: Lab 3: Version control and collaboration...What is version control? Distributed Snapshots Storage landscape Using Git Gitting started... commit branch merge Merge con icts Exploration

Introduction

What is versioncontrol?

Distributed

Snapshots

Storagelandscape

Using Git

Gitting started...

commit

branch

merge

Merge conflicts

Exploration

Remoterepositories

Industrialworkflow

Final tips

Branching

a

b

c

d

master

new-branch $ HEAD

Page 22: Lab 3: Version control and collaboration...What is version control? Distributed Snapshots Storage landscape Using Git Gitting started... commit branch merge Merge con icts Exploration

Introduction

What is versioncontrol?

Distributed

Snapshots

Storagelandscape

Using Git

Gitting started...

commit

branch

merge

Merge conflicts

Exploration

Remoterepositories

Industrialworkflow

Final tips

Branching

$ git checkout master

a

b

c

d

master

new-branch

$ HEAD

Page 23: Lab 3: Version control and collaboration...What is version control? Distributed Snapshots Storage landscape Using Git Gitting started... commit branch merge Merge con icts Exploration

Introduction

What is versioncontrol?

Distributed

Snapshots

Storagelandscape

Using Git

Gitting started...

commit

branch

merge

Merge conflicts

Exploration

Remoterepositories

Industrialworkflow

Final tips

Branching

$ git checkout -b another

a

b

c

d

master

new-branch

$ HEADanother

Page 24: Lab 3: Version control and collaboration...What is version control? Distributed Snapshots Storage landscape Using Git Gitting started... commit branch merge Merge con icts Exploration

Introduction

What is versioncontrol?

Distributed

Snapshots

Storagelandscape

Using Git

Gitting started...

commit

branch

merge

Merge conflicts

Exploration

Remoterepositories

Industrialworkflow

Final tips

Branching

$ git commit -m ‘‘e’’

a

b

c

d e

master

new-branch $ HEADanother

Page 25: Lab 3: Version control and collaboration...What is version control? Distributed Snapshots Storage landscape Using Git Gitting started... commit branch merge Merge con icts Exploration

Introduction

What is versioncontrol?

Distributed

Snapshots

Storagelandscape

Using Git

Gitting started...

commit

branch

merge

Merge conflicts

Exploration

Remoterepositories

Industrialworkflow

Final tips

Outline

1 IntroductionWhat is version control?DistributedSnapshotsStorage landscape

2 Using GitGitting started...commitbranchmerge

Merge conflictsExplorationRemote repositoriesIndustrial workflowFinal tips

Page 26: Lab 3: Version control and collaboration...What is version control? Distributed Snapshots Storage landscape Using Git Gitting started... commit branch merge Merge con icts Exploration

Introduction

What is versioncontrol?

Distributed

Snapshots

Storagelandscape

Using Git

Gitting started...

commit

branch

merge

Merge conflicts

Exploration

Remoterepositories

Industrialworkflow

Final tips

Merging

$ git merge new-branch

a

b

c

d e

master

new-branch $ HEADanother

Page 27: Lab 3: Version control and collaboration...What is version control? Distributed Snapshots Storage landscape Using Git Gitting started... commit branch merge Merge con icts Exploration

Introduction

What is versioncontrol?

Distributed

Snapshots

Storagelandscape

Using Git

Gitting started...

commit

branch

merge

Merge conflicts

Exploration

Remoterepositories

Industrialworkflow

Final tips

Merging

$ git merge new-branch

a

b

c

d e

d+e

master

new-branch

Page 28: Lab 3: Version control and collaboration...What is version control? Distributed Snapshots Storage landscape Using Git Gitting started... commit branch merge Merge con icts Exploration

Introduction

What is versioncontrol?

Distributed

Snapshots

Storagelandscape

Using Git

Gitting started...

commit

branch

merge

Merge conflicts

Exploration

Remoterepositories

Industrialworkflow

Final tips

Merging

$ git merge new-branch

a

b

c

d e

d+e

master

new-branch

$ HEADanother

Page 29: Lab 3: Version control and collaboration...What is version control? Distributed Snapshots Storage landscape Using Git Gitting started... commit branch merge Merge con icts Exploration

Introduction

What is versioncontrol?

Distributed

Snapshots

Storagelandscape

Using Git

Gitting started...

commit

branch

merge

Merge conflicts

Exploration

Remoterepositories

Industrialworkflow

Final tips

Merging

$ git merge master

$ Nothing to do! a

b

c

d e

d+e

master

new-branch

$ HEADanother

Page 30: Lab 3: Version control and collaboration...What is version control? Distributed Snapshots Storage landscape Using Git Gitting started... commit branch merge Merge con icts Exploration

Introduction

What is versioncontrol?

Distributed

Snapshots

Storagelandscape

Using Git

Gitting started...

commit

branch

merge

Merge conflicts

Exploration

Remoterepositories

Industrialworkflow

Final tips

Merging

$ git checkout master

a

b

c

d e

d+e

master

new-branch

another

$ HEAD

Page 31: Lab 3: Version control and collaboration...What is version control? Distributed Snapshots Storage landscape Using Git Gitting started... commit branch merge Merge con icts Exploration

Introduction

What is versioncontrol?

Distributed

Snapshots

Storagelandscape

Using Git

Gitting started...

commit

branch

merge

Merge conflicts

Exploration

Remoterepositories

Industrialworkflow

Final tips

Merging

$ git merge another

a

b

c

d e

d+e

master

new-branch

$ HEADanother

Page 32: Lab 3: Version control and collaboration...What is version control? Distributed Snapshots Storage landscape Using Git Gitting started... commit branch merge Merge con icts Exploration

Introduction

What is versioncontrol?

Distributed

Snapshots

Storagelandscape

Using Git

Gitting started...

commit

branch

merge

Merge conflicts

Exploration

Remoterepositories

Industrialworkflow

Final tips

Merge conflicts

CONFLICT (content): Merge conflict in

the-file.txt

Automatic merge failed; fix conflicts and then

commit the result.

In the-file.txt :<<<<<<< HEAD

The current branch’s contents

=======

Stuff from the branch you’re merging

>>>>>>> new-branch

$ git add the-file.txt and $ git commit

Page 33: Lab 3: Version control and collaboration...What is version control? Distributed Snapshots Storage landscape Using Git Gitting started... commit branch merge Merge con icts Exploration

Introduction

What is versioncontrol?

Distributed

Snapshots

Storagelandscape

Using Git

Gitting started...

commit

branch

merge

Merge conflicts

Exploration

Remoterepositories

Industrialworkflow

Final tips

Outline

1 IntroductionWhat is version control?DistributedSnapshotsStorage landscape

2 Using GitGitting started...commitbranchmerge

Merge conflictsExplorationRemote repositoriesIndustrial workflowFinal tips

Page 34: Lab 3: Version control and collaboration...What is version control? Distributed Snapshots Storage landscape Using Git Gitting started... commit branch merge Merge con icts Exploration

Introduction

What is versioncontrol?

Distributed

Snapshots

Storagelandscape

Using Git

Gitting started...

commit

branch

merge

Merge conflicts

Exploration

Remoterepositories

Industrialworkflow

Final tips

Looking at stuff

• $ git log Show a log of commits

• --graph Neat ASCII graph

• -p Show what changed in each commit

• $ git diff Show uncommitted changes

• $ gitk Graphical log

• --all Show all branches

• $ git gui Graphical tool for committing

Page 35: Lab 3: Version control and collaboration...What is version control? Distributed Snapshots Storage landscape Using Git Gitting started... commit branch merge Merge con icts Exploration

Introduction

What is versioncontrol?

Distributed

Snapshots

Storagelandscape

Using Git

Gitting started...

commit

branch

merge

Merge conflicts

Exploration

Remoterepositories

Industrialworkflow

Final tips

Outline

1 IntroductionWhat is version control?DistributedSnapshotsStorage landscape

2 Using GitGitting started...commitbranchmerge

Merge conflictsExplorationRemote repositoriesIndustrial workflowFinal tips

Page 36: Lab 3: Version control and collaboration...What is version control? Distributed Snapshots Storage landscape Using Git Gitting started... commit branch merge Merge con icts Exploration

Introduction

What is versioncontrol?

Distributed

Snapshots

Storagelandscape

Using Git

Gitting started...

commit

branch

merge

Merge conflicts

Exploration

Remoterepositories

Industrialworkflow

Final tips

Working with remotes

• $ git clone <REPO URL> makes a copy of a repository.

• $ git push Pushes changes from your current branch tothe remote branch it tracks.(You may need to run$ git config --global push.default simple .)

• $ git pull Pulls changes from the remote branch andmerges them into your current branch.

• $ git remote add <REMOTE NAME> <REPO URL> addsa remote to an existing repository.

Page 37: Lab 3: Version control and collaboration...What is version control? Distributed Snapshots Storage landscape Using Git Gitting started... commit branch merge Merge con icts Exploration

Introduction

What is versioncontrol?

Distributed

Snapshots

Storagelandscape

Using Git

Gitting started...

commit

branch

merge

Merge conflicts

Exploration

Remoterepositories

Industrialworkflow

Final tips

Outline

1 IntroductionWhat is version control?DistributedSnapshotsStorage landscape

2 Using GitGitting started...commitbranchmerge

Merge conflictsExplorationRemote repositoriesIndustrial workflowFinal tips

Page 38: Lab 3: Version control and collaboration...What is version control? Distributed Snapshots Storage landscape Using Git Gitting started... commit branch merge Merge con icts Exploration

Introduction

What is versioncontrol?

Distributed

Snapshots

Storagelandscape

Using Git

Gitting started...

commit

branch

merge

Merge conflicts

Exploration

Remoterepositories

Industrialworkflow

Final tips

Collaboration

• You and your co-workers are working on a projectsimultaneously

• You clone the company’s repository:$ git clone https://git.company.com/project.git

• $ git checkout -b doug to create your owndevelopment branch

• Modify files, $ git add <FILENAME> to stage them,

$ git commit when they are in a working state.

• Ready to merge with mainline?$ git checkout master and $ git merge doug .

• Your work is now merged with your local master branch(but not on the company’s repo).

• Question: which branch is HEAD now pointing to?

Page 39: Lab 3: Version control and collaboration...What is version control? Distributed Snapshots Storage landscape Using Git Gitting started... commit branch merge Merge con icts Exploration

Introduction

What is versioncontrol?

Distributed

Snapshots

Storagelandscape

Using Git

Gitting started...

commit

branch

merge

Merge conflicts

Exploration

Remoterepositories

Industrialworkflow

Final tips

Collaboration

• Meanwhile, your co-workers might have made changes!

• First, $ git pull to fetch and merge their changes

• Rectify merge conflicts, test the code, then$ git add <FILENAME> to stage, and then

$ git commit when in a working state

• Only after pulling and merging the most recent changesshould you $ git push

• Your work is merged with that of your co-workers, andnow resides on the company repo

• Take a coffee break.

Page 40: Lab 3: Version control and collaboration...What is version control? Distributed Snapshots Storage landscape Using Git Gitting started... commit branch merge Merge con icts Exploration

Introduction

What is versioncontrol?

Distributed

Snapshots

Storagelandscape

Using Git

Gitting started...

commit

branch

merge

Merge conflicts

Exploration

Remoterepositories

Industrialworkflow

Final tips

Outline

1 IntroductionWhat is version control?DistributedSnapshotsStorage landscape

2 Using GitGitting started...commitbranchmerge

Merge conflictsExplorationRemote repositoriesIndustrial workflowFinal tips

Page 41: Lab 3: Version control and collaboration...What is version control? Distributed Snapshots Storage landscape Using Git Gitting started... commit branch merge Merge con icts Exploration

Introduction

What is versioncontrol?

Distributed

Snapshots

Storagelandscape

Using Git

Gitting started...

commit

branch

merge

Merge conflicts

Exploration

Remoterepositories

Industrialworkflow

Final tips

Git Tips

• Make your commit messages descriptive!

• Only $ git commit when the code works!

• Don’t add generated files (like a.out ) to your repo.

• You can ignore certain files by putting their names in a.gitignore file in your repo.

• When collaborating, work on separate branches and mergeas you go along.

• $ git help COMMAND will show you documentation.