introduction to git - gnugeneration.epfl.chdesroche/... · table of contents 1 the problem 2 about...

29
Introduction to git Joachim Desroches GNU Generation 2018-10-01 Joachim Desroches (GNU Generation) Introduction to git 2018-10-01 1 / 14

Upload: others

Post on 03-Jul-2020

10 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Introduction to git - gnugeneration.epfl.chdesroche/... · Table of Contents 1 The Problem 2 About git 3 Using git 4 Collaborate 5 Common mistakes 6 Practice time Joachim Desroches

Introduction to git

Joachim Desroches

GNU Generation

2018-10-01

Joachim Desroches (GNU Generation) Introduction to git 2018-10-01 1 / 14

Page 2: Introduction to git - gnugeneration.epfl.chdesroche/... · Table of Contents 1 The Problem 2 About git 3 Using git 4 Collaborate 5 Common mistakes 6 Practice time Joachim Desroches

Joachim Desroches (GNU Generation) Introduction to git 2018-10-01 2 / 14

Page 3: Introduction to git - gnugeneration.epfl.chdesroche/... · Table of Contents 1 The Problem 2 About git 3 Using git 4 Collaborate 5 Common mistakes 6 Practice time Joachim Desroches

Table of Contents

1 The Problem

2 About git

3 Using git

4 Collaborate

5 Common mistakes

6 Practice time

Joachim Desroches (GNU Generation) Introduction to git 2018-10-01 3 / 14

Page 4: Introduction to git - gnugeneration.epfl.chdesroche/... · Table of Contents 1 The Problem 2 About git 3 Using git 4 Collaborate 5 Common mistakes 6 Practice time Joachim Desroches

The Problem

Version Hell

Joachim Desroches (GNU Generation) Introduction to git 2018-10-01 4 / 14

Page 5: Introduction to git - gnugeneration.epfl.chdesroche/... · Table of Contents 1 The Problem 2 About git 3 Using git 4 Collaborate 5 Common mistakes 6 Practice time Joachim Desroches

About git

Version Control

Make the computer do the work.

Several exist: git, SVN, CVS, Mercurial...

Git created to track Linux kernel, most commonly used.

Do NOT confuse with project management systems like MicrosoftGithub or Gitlab!

Joachim Desroches (GNU Generation) Introduction to git 2018-10-01 5 / 14

Page 6: Introduction to git - gnugeneration.epfl.chdesroche/... · Table of Contents 1 The Problem 2 About git 3 Using git 4 Collaborate 5 Common mistakes 6 Practice time Joachim Desroches

About git

Version Control

Make the computer do the work.

Several exist: git, SVN, CVS, Mercurial...

Git created to track Linux kernel, most commonly used.

Do NOT confuse with project management systems like MicrosoftGithub or Gitlab!

Joachim Desroches (GNU Generation) Introduction to git 2018-10-01 5 / 14

Page 7: Introduction to git - gnugeneration.epfl.chdesroche/... · Table of Contents 1 The Problem 2 About git 3 Using git 4 Collaborate 5 Common mistakes 6 Practice time Joachim Desroches

About git

Version Control

Make the computer do the work.

Several exist: git, SVN, CVS, Mercurial...

Git created to track Linux kernel, most commonly used.

Do NOT confuse with project management systems like MicrosoftGithub or Gitlab!

Joachim Desroches (GNU Generation) Introduction to git 2018-10-01 5 / 14

Page 8: Introduction to git - gnugeneration.epfl.chdesroche/... · Table of Contents 1 The Problem 2 About git 3 Using git 4 Collaborate 5 Common mistakes 6 Practice time Joachim Desroches

About git

Version Control

Make the computer do the work.

Several exist: git, SVN, CVS, Mercurial...

Git created to track Linux kernel, most commonly used.

Do NOT confuse with project management systems like MicrosoftGithub or Gitlab!

Joachim Desroches (GNU Generation) Introduction to git 2018-10-01 5 / 14

Page 9: Introduction to git - gnugeneration.epfl.chdesroche/... · Table of Contents 1 The Problem 2 About git 3 Using git 4 Collaborate 5 Common mistakes 6 Practice time Joachim Desroches

Using git

Tracking changes

Let us start locally. There are three things you want to do:

Start using git! git init . and git status

Add and save changes: git add <file> and git commit

Review changes: git log, git diff and git checkout

Joachim Desroches (GNU Generation) Introduction to git 2018-10-01 6 / 14

Page 10: Introduction to git - gnugeneration.epfl.chdesroche/... · Table of Contents 1 The Problem 2 About git 3 Using git 4 Collaborate 5 Common mistakes 6 Practice time Joachim Desroches

Using git

Tracking changes

Let us start locally. There are three things you want to do:

Start using git! git init . and git status

Add and save changes: git add <file> and git commit

Review changes: git log, git diff and git checkout

Joachim Desroches (GNU Generation) Introduction to git 2018-10-01 6 / 14

Page 11: Introduction to git - gnugeneration.epfl.chdesroche/... · Table of Contents 1 The Problem 2 About git 3 Using git 4 Collaborate 5 Common mistakes 6 Practice time Joachim Desroches

Using git

Tracking changes

Let us start locally. There are three things you want to do:

Start using git! git init . and git status

Add and save changes: git add <file> and git commit

Review changes: git log, git diff and git checkout

Joachim Desroches (GNU Generation) Introduction to git 2018-10-01 6 / 14

Page 12: Introduction to git - gnugeneration.epfl.chdesroche/... · Table of Contents 1 The Problem 2 About git 3 Using git 4 Collaborate 5 Common mistakes 6 Practice time Joachim Desroches

Collaborate

And then they were two

What happens if there are several of us ?

Needs some centrally accessible machine.

Helps to use a frontend like Gitlab.

Interacting: git push, git pull, merging.

We will see this in more detail in the practical part.

Joachim Desroches (GNU Generation) Introduction to git 2018-10-01 7 / 14

Page 13: Introduction to git - gnugeneration.epfl.chdesroche/... · Table of Contents 1 The Problem 2 About git 3 Using git 4 Collaborate 5 Common mistakes 6 Practice time Joachim Desroches

Collaborate

And then they were two

What happens if there are several of us ?

Needs some centrally accessible machine.

Helps to use a frontend like Gitlab.

Interacting: git push, git pull, merging.

We will see this in more detail in the practical part.

Joachim Desroches (GNU Generation) Introduction to git 2018-10-01 7 / 14

Page 14: Introduction to git - gnugeneration.epfl.chdesroche/... · Table of Contents 1 The Problem 2 About git 3 Using git 4 Collaborate 5 Common mistakes 6 Practice time Joachim Desroches

Collaborate

And then they were two

What happens if there are several of us ?

Needs some centrally accessible machine.

Helps to use a frontend like Gitlab.

Interacting: git push, git pull, merging.

We will see this in more detail in the practical part.

Joachim Desroches (GNU Generation) Introduction to git 2018-10-01 7 / 14

Page 15: Introduction to git - gnugeneration.epfl.chdesroche/... · Table of Contents 1 The Problem 2 About git 3 Using git 4 Collaborate 5 Common mistakes 6 Practice time Joachim Desroches

Collaborate

And then they were two

What happens if there are several of us ?

Needs some centrally accessible machine.

Helps to use a frontend like Gitlab.

Interacting: git push, git pull, merging.

We will see this in more detail in the practical part.

Joachim Desroches (GNU Generation) Introduction to git 2018-10-01 7 / 14

Page 16: Introduction to git - gnugeneration.epfl.chdesroche/... · Table of Contents 1 The Problem 2 About git 3 Using git 4 Collaborate 5 Common mistakes 6 Practice time Joachim Desroches

Common mistakes

Some confusions that occur often

Trying to remove things from git.

Trying to modify a commit when history is shared.

Not fixing conflicts properly.

Joachim Desroches (GNU Generation) Introduction to git 2018-10-01 8 / 14

Page 17: Introduction to git - gnugeneration.epfl.chdesroche/... · Table of Contents 1 The Problem 2 About git 3 Using git 4 Collaborate 5 Common mistakes 6 Practice time Joachim Desroches

Common mistakes

Some confusions that occur often

Trying to remove things from git.

Trying to modify a commit when history is shared.

Not fixing conflicts properly.

Joachim Desroches (GNU Generation) Introduction to git 2018-10-01 8 / 14

Page 18: Introduction to git - gnugeneration.epfl.chdesroche/... · Table of Contents 1 The Problem 2 About git 3 Using git 4 Collaborate 5 Common mistakes 6 Practice time Joachim Desroches

Common mistakes

Some confusions that occur often

Trying to remove things from git.

Trying to modify a commit when history is shared.

Not fixing conflicts properly.

Joachim Desroches (GNU Generation) Introduction to git 2018-10-01 8 / 14

Page 19: Introduction to git - gnugeneration.epfl.chdesroche/... · Table of Contents 1 The Problem 2 About git 3 Using git 4 Collaborate 5 Common mistakes 6 Practice time Joachim Desroches

Practice time

Please pair up! (Groups of 3 are ok) Then head over tohttp://gitlab.gnugen.ch

Joachim Desroches (GNU Generation) Introduction to git 2018-10-01 9 / 14

Page 20: Introduction to git - gnugeneration.epfl.chdesroche/... · Table of Contents 1 The Problem 2 About git 3 Using git 4 Collaborate 5 Common mistakes 6 Practice time Joachim Desroches

Practice time

One of you should create a new project, choosing to initialize it with aREADME and add the other as at least a developper. Then follow theinstructions to clone the repository on your machines.

Joachim Desroches (GNU Generation) Introduction to git 2018-10-01 10 / 14

Page 21: Introduction to git - gnugeneration.epfl.chdesroche/... · Table of Contents 1 The Problem 2 About git 3 Using git 4 Collaborate 5 Common mistakes 6 Practice time Joachim Desroches

Practice time

Make some changes each, and track them! Remember, you can use:

git add <myfile> in order to set a changed file in this snapshot.

git commit to snapshot the files.

git log to see what has happened until now.

Joachim Desroches (GNU Generation) Introduction to git 2018-10-01 11 / 14

Page 22: Introduction to git - gnugeneration.epfl.chdesroche/... · Table of Contents 1 The Problem 2 About git 3 Using git 4 Collaborate 5 Common mistakes 6 Practice time Joachim Desroches

Practice time

Now, one of you can use git push to send his work to the server. Go thewebpage of your project, and see that you can indeed see the changes.The second should try to push as well: does this work ?

Joachim Desroches (GNU Generation) Introduction to git 2018-10-01 12 / 14

Page 23: Introduction to git - gnugeneration.epfl.chdesroche/... · Table of Contents 1 The Problem 2 About git 3 Using git 4 Collaborate 5 Common mistakes 6 Practice time Joachim Desroches

Practice time

git pull: you will start a merge.

git status, git add to resolve: open the files and look for lineswith >>>>>,===== and <<<<<<<.

Finally use git commit to finish, and push your changes!

Your partner can now pull: this time, there should be no conflict.

Joachim Desroches (GNU Generation) Introduction to git 2018-10-01 13 / 14

Page 24: Introduction to git - gnugeneration.epfl.chdesroche/... · Table of Contents 1 The Problem 2 About git 3 Using git 4 Collaborate 5 Common mistakes 6 Practice time Joachim Desroches

Practice time

git pull: you will start a merge.

git status, git add to resolve: open the files and look for lineswith >>>>>,===== and <<<<<<<.

Finally use git commit to finish, and push your changes!

Your partner can now pull: this time, there should be no conflict.

Joachim Desroches (GNU Generation) Introduction to git 2018-10-01 13 / 14

Page 25: Introduction to git - gnugeneration.epfl.chdesroche/... · Table of Contents 1 The Problem 2 About git 3 Using git 4 Collaborate 5 Common mistakes 6 Practice time Joachim Desroches

Practice time

git pull: you will start a merge.

git status, git add to resolve: open the files and look for lineswith >>>>>,===== and <<<<<<<.

Finally use git commit to finish, and push your changes!

Your partner can now pull: this time, there should be no conflict.

Joachim Desroches (GNU Generation) Introduction to git 2018-10-01 13 / 14

Page 26: Introduction to git - gnugeneration.epfl.chdesroche/... · Table of Contents 1 The Problem 2 About git 3 Using git 4 Collaborate 5 Common mistakes 6 Practice time Joachim Desroches

Practice time

Conclusion

Remember man pages are your friend!

Read the Git Book: more depth and more possibilities

Most of all, use git! Practice makes perfect.

Questions ?

Joachim Desroches (GNU Generation) Introduction to git 2018-10-01 14 / 14

Page 27: Introduction to git - gnugeneration.epfl.chdesroche/... · Table of Contents 1 The Problem 2 About git 3 Using git 4 Collaborate 5 Common mistakes 6 Practice time Joachim Desroches

Practice time

Conclusion

Remember man pages are your friend!

Read the Git Book: more depth and more possibilities

Most of all, use git! Practice makes perfect.

Questions ?

Joachim Desroches (GNU Generation) Introduction to git 2018-10-01 14 / 14

Page 28: Introduction to git - gnugeneration.epfl.chdesroche/... · Table of Contents 1 The Problem 2 About git 3 Using git 4 Collaborate 5 Common mistakes 6 Practice time Joachim Desroches

Practice time

Conclusion

Remember man pages are your friend!

Read the Git Book: more depth and more possibilities

Most of all, use git! Practice makes perfect.

Questions ?

Joachim Desroches (GNU Generation) Introduction to git 2018-10-01 14 / 14

Page 29: Introduction to git - gnugeneration.epfl.chdesroche/... · Table of Contents 1 The Problem 2 About git 3 Using git 4 Collaborate 5 Common mistakes 6 Practice time Joachim Desroches

Practice time

Conclusion

Remember man pages are your friend!

Read the Git Book: more depth and more possibilities

Most of all, use git! Practice makes perfect.

Questions ?

Joachim Desroches (GNU Generation) Introduction to git 2018-10-01 14 / 14