what is version control?nmjxv3/cs1001/archives/2016sp/03-version_control.pdfgetting started i git...

31
What is version control? I Keeps track of changes to your code. I You don’t have to worry about accidentally losing or deleting code. I You can experiment and reset to a known good state. I Makes collaborating with others easier.

Upload: others

Post on 26-May-2020

19 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: What is version control?nmjxv3/cs1001/archives/2016SP/03-version_control.pdfGetting Started I git init Makes a new empty git repository. I git add FILE Adds changes in FILE to the

What is version control?

I Keeps track of changes to your code.

I You don’t have to worry about accidentally losing or deletingcode.

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

I Makes collaborating with others easier.

What is git?

I ‘the stupid content tracker’

I Distributed - everything is kept on your local machine.

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

I ‘Commit’ - a chunk of saved changes.

Page 2: What is version control?nmjxv3/cs1001/archives/2016SP/03-version_control.pdfGetting Started I git init Makes a new empty git repository. I git add FILE Adds changes in FILE to the

What is version control?

I Keeps track of changes to your code.

I You don’t have to worry about accidentally losing or deletingcode.

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

I Makes collaborating with others easier.

What is git?

I ‘the stupid content tracker’

I Distributed - everything is kept on your local machine.

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

I ‘Commit’ - a chunk of saved changes.

Page 3: What is version control?nmjxv3/cs1001/archives/2016SP/03-version_control.pdfGetting Started I git init Makes a new empty git repository. I git add FILE Adds changes in FILE to the

Getting Started

I git init Makes a new empty git repository.

I git add FILE Adds changes in FILE to the next commit.

I git status Shows the status of the repository.

I git config --global user.name NAME

I git config --global user.email EMAIL

I git config --global core.editor vim

Page 4: What is version control?nmjxv3/cs1001/archives/2016SP/03-version_control.pdfGetting Started I git init Makes a new empty git repository. I git add FILE Adds changes in FILE to the

Getting Started

I git init Makes a new empty git repository.

I git add FILE Adds changes in FILE to the next commit.

I git status Shows the status of the repository.

I git config --global user.name NAME

I git config --global user.email EMAIL

I git config --global core.editor vim

Page 5: What is version control?nmjxv3/cs1001/archives/2016SP/03-version_control.pdfGetting Started I git init Makes a new empty git repository. I git add FILE Adds changes in FILE to the

Committing

git commit -m ‘‘a’’

amaster

Page 6: What is version control?nmjxv3/cs1001/archives/2016SP/03-version_control.pdfGetting Started I git init Makes a new empty git repository. I git add FILE Adds changes in FILE to the

Committing

git commit -m ‘‘b’’

a

bmaster

Page 7: What is version control?nmjxv3/cs1001/archives/2016SP/03-version_control.pdfGetting Started I git init Makes a new empty git repository. I git add FILE Adds changes in FILE to the

Committing

git commit -m ‘‘c’’

a

b

cmaster

Page 8: What is version control?nmjxv3/cs1001/archives/2016SP/03-version_control.pdfGetting Started I git init Makes a new empty git repository. I git add FILE Adds changes in FILE to the

Branching

git checkout -b new-branch

a

b

c

master

new-branch

Page 9: What is version control?nmjxv3/cs1001/archives/2016SP/03-version_control.pdfGetting Started I git init Makes a new empty git repository. I git add FILE Adds changes in FILE to the

Branching

git commit -m ‘‘d’’

a

b

c

d

master

new-branch

Page 10: What is version control?nmjxv3/cs1001/archives/2016SP/03-version_control.pdfGetting Started I git init Makes a new empty git repository. I git add FILE Adds changes in FILE to the

Branching

a

b

c

d

master

new-branch HEAD

Page 11: What is version control?nmjxv3/cs1001/archives/2016SP/03-version_control.pdfGetting Started I git init Makes a new empty git repository. I git add FILE Adds changes in FILE to the

Branching

git checkout master

a

b

c

d

master

new-branch

HEAD

Page 12: What is version control?nmjxv3/cs1001/archives/2016SP/03-version_control.pdfGetting Started I git init Makes a new empty git repository. I git add FILE Adds changes in FILE to the

Branching

git checkout -b another

a

b

c

d

master

new-branch

HEADanother

Page 13: What is version control?nmjxv3/cs1001/archives/2016SP/03-version_control.pdfGetting Started I git init Makes a new empty git repository. I git add FILE Adds changes in FILE to the

Branching

git commit -m ‘‘e’’

a

b

c

d e

master

new-branch HEADanother

Page 14: What is version control?nmjxv3/cs1001/archives/2016SP/03-version_control.pdfGetting Started I git init Makes a new empty git repository. I git add FILE Adds changes in FILE to the

Merging

git merge new-branch

a

b

c

d e

master

new-branch HEADanother

Page 15: What is version control?nmjxv3/cs1001/archives/2016SP/03-version_control.pdfGetting Started I git init Makes a new empty git repository. I git add FILE Adds changes in FILE to the

Merginggit merge new-branch

a

b

c

d e

d+e

master

new-branch

Page 16: What is version control?nmjxv3/cs1001/archives/2016SP/03-version_control.pdfGetting Started I git init Makes a new empty git repository. I git add FILE Adds changes in FILE to the

Merginggit merge new-branch

a

b

c

d e

d+e

master

new-branch

HEADanother

Page 17: What is version control?nmjxv3/cs1001/archives/2016SP/03-version_control.pdfGetting Started I git init Makes a new empty git repository. I git add FILE Adds changes in FILE to the

Merginggit merge master

Nothing to do!a

b

c

d e

d+e

master

new-branch

HEADanother

Page 18: What is version control?nmjxv3/cs1001/archives/2016SP/03-version_control.pdfGetting Started I git init Makes a new empty git repository. I git add FILE Adds changes in FILE to the

Merginggit checkout master

a

b

c

d e

d+e

master

new-branch

another

HEAD

Page 19: What is version control?nmjxv3/cs1001/archives/2016SP/03-version_control.pdfGetting Started I git init Makes a new empty git repository. I git add FILE Adds changes in FILE to the

Merginggit merge another

a

b

c

d e

d+e

master

new-branch

HEADanother

Page 20: What is version control?nmjxv3/cs1001/archives/2016SP/03-version_control.pdfGetting Started I git init Makes a new empty git repository. I git add FILE Adds changes in FILE to the

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 21: What is version control?nmjxv3/cs1001/archives/2016SP/03-version_control.pdfGetting Started I git init Makes a new empty git repository. I git add FILE Adds changes in FILE to the

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 22: What is version control?nmjxv3/cs1001/archives/2016SP/03-version_control.pdfGetting Started I git init Makes a new empty git repository. I git add FILE Adds changes in FILE to the

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 23: What is version control?nmjxv3/cs1001/archives/2016SP/03-version_control.pdfGetting Started I git init Makes a new empty git repository. I git add FILE Adds changes in FILE to the

Looking at stuff

I git log Show a log of commits

I --graph Neat ASCII graph

I -p Show what changed in each commit

I git diff Show uncommitted changes

I gitk Graphical log

I --all Show all branches

I git gui Graphical tool for committing

Page 24: What is version control?nmjxv3/cs1001/archives/2016SP/03-version_control.pdfGetting Started I git init Makes a new empty git repository. I git add FILE Adds changes in FILE to the

Looking at stuff

I git log Show a log of commits

I --graph Neat ASCII graph

I -p Show what changed in each commit

I git diff Show uncommitted changes

I gitk Graphical log

I --all Show all branches

I git gui Graphical tool for committing

Page 25: What is version control?nmjxv3/cs1001/archives/2016SP/03-version_control.pdfGetting Started I git init Makes a new empty git repository. I git add FILE Adds changes in FILE to the

Looking at stuff

I git log Show a log of commits

I --graph Neat ASCII graph

I -p Show what changed in each commit

I git diff Show uncommitted changes

I gitk Graphical log

I --all Show all branches

I git gui Graphical tool for committing

Page 26: What is version control?nmjxv3/cs1001/archives/2016SP/03-version_control.pdfGetting Started I git init Makes a new empty git repository. I git add FILE Adds changes in FILE to the

Working with remotes

I git clone REPO LOCATION makes a copy of a repository.

I git push Pushes changes from your current branch to theremote branch it tracks.(You may need to rungit config --global push.default simple .)

I git pull Pulls changes from the remote branch and mergesthem into your current branch.

I git remote add REMOTE NAME REPO LOCATION adds aremote to an existing repository.

Page 27: What is version control?nmjxv3/cs1001/archives/2016SP/03-version_control.pdfGetting Started I git init Makes a new empty git repository. I git add FILE Adds changes in FILE to the

Working with remotes

I git clone REPO LOCATION makes a copy of a repository.

I git push Pushes changes from your current branch to theremote branch it tracks.(You may need to rungit config --global push.default simple .)

I git pull Pulls changes from the remote branch and mergesthem into your current branch.

I git remote add REMOTE NAME REPO LOCATION adds aremote to an existing repository.

Page 28: What is version control?nmjxv3/cs1001/archives/2016SP/03-version_control.pdfGetting Started I git init Makes a new empty git repository. I git add FILE Adds changes in FILE to the

Working with remotes

I git clone REPO LOCATION makes a copy of a repository.

I git push Pushes changes from your current branch to theremote branch it tracks.(You may need to rungit config --global push.default simple .)

I git pull Pulls changes from the remote branch and mergesthem into your current branch.

I git remote add REMOTE NAME REPO LOCATION adds aremote to an existing repository.

Page 29: What is version control?nmjxv3/cs1001/archives/2016SP/03-version_control.pdfGetting Started I git init Makes a new empty git repository. I git add FILE Adds changes in FILE to the

Git Tips

I Make your commit messages descriptive!

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

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

I When collaborating, work on separate branches and merge asyou go along.

I git help COMMAND will show you documentation.

Page 30: What is version control?nmjxv3/cs1001/archives/2016SP/03-version_control.pdfGetting Started I git init Makes a new empty git repository. I git add FILE Adds changes in FILE to the

Git Tips

I Make your commit messages descriptive!

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

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

I When collaborating, work on separate branches and merge asyou go along.

I git help COMMAND will show you documentation.

Page 31: What is version control?nmjxv3/cs1001/archives/2016SP/03-version_control.pdfGetting Started I git init Makes a new empty git repository. I git add FILE Adds changes in FILE to the

Git Tips

I Make your commit messages descriptive!

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

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

I When collaborating, work on separate branches and merge asyou go along.

I git help COMMAND will show you documentation.