Introduction to gitGit on Windows What if I use Windows? I msysgit (installs a shell and works just...

Post on 10-Jul-2020

9 views 0 download

Transcript of Introduction to gitGit on Windows What if I use Windows? I msysgit (installs a shell and works just...

Introduction to gitA lecture arranged by Ludd and Arctic Group

Anders Engstrom

7 April 2016

1 / 27

Overview

IntroductionIn a world without versioncontrolTypes of version controlThis is git

Getting startedPreparationsYour own repositoryFirst time with a repositoryConnect more users

Using git

Everyday useTagsBranchingUndoA closer look at the historyIgnoring filesGit on Windows

ConclusionSummaryBibliography and linksQuestions and comments

2 / 27

Overview

IntroductionIn a world without versioncontrolTypes of version controlThis is git

Getting startedPreparationsYour own repositoryFirst time with a repositoryConnect more users

Using git

Everyday useTagsBranchingUndoA closer look at the historyIgnoring filesGit on Windows

ConclusionSummaryBibliography and linksQuestions and comments

3 / 27

In a world without version control

How do you work in a group?

I Shared folder.

I Mail files back and fourth. (All files or only changed ones?)

I Instant messaging.

How do you undo changes?

I Rewrite parts of the code so that it looks the same as before.

I Create a copy in advance according to a naming convention.

I Search through old mails.

Can you come up with any more ways?

4 / 27

Types of version control

How do you handle multiple users?

I File locks

I Merge

Where is the information stored?

I Centralized

I Distributed

5 / 27

This is git

Git is:

I A fast distributed version control system.

I Written for the Linux kernel (by Linus Torvalds et al.)

I Lots of other projects also use it.

I Git is open source, GPL etc.

We will look at:

I Mostly the official command-line client. (Also available forWindows.)

I A little bit of a graphical client. (The concepts are the same.)

6 / 27

Overview

IntroductionIn a world without versioncontrolTypes of version controlThis is git

Getting startedPreparationsYour own repositoryFirst time with a repositoryConnect more users

Using git

Everyday useTagsBranchingUndoA closer look at the historyIgnoring filesGit on Windows

ConclusionSummaryBibliography and linksQuestions and comments

7 / 27

Preparations

Who are you?

1 g i t c o n f i g −−g l o b a l u s e r . name ”Anders Engs t r om”2 g i t c o n f i g −−g l o b a l u s e r . ema i l ankan@ludd . l t u . s e

Create a common storage area

I Many sites offer free hosting. (Github, Bitbucket, Ludd)Create an account and a repository there.

I Or create your own on a server. (All you need is a directory allusers can access.)

8 / 27

Your own repository

Create your own repository (on a server):

1 g i t i n i t −−bare −−sha r ed t e s t . g i t2 groupadd t e s t p r o j e c t3 chgrp −R t e s t p r o j e c t t e s t . g i t4 chmod −R 770 t e s t . g i t

9 / 27

To begin putting stuff in there

Prepare a simple repository to upload (on aclient machine.):

1 g i t i n i t t e s t2 cd te s t3 touch README4 g i t add README5 g i t commit −m ’ f i r s t commit ’

10 / 27

Connect with the server for the first time

Bitbucket:

1 g i t remote add o r i g i n h t t p s : // ankaan@b i tbucket . org /ankaan/ t e s t . g i t

Github:

1 g i t remote add o r i g i n g i t@g i t h ub . com : ankaan/ t e s t . g i t

Your own server:

1 g i t remote add o r i g i n ankan@ l o ca l ho s t : t e s t . g i t

Upload:

1 g i t push −u o r i g i n master

11 / 27

Connect more users

To connect more users beyond the first, use:

1 g i t c l o n e ankan@ lo ca l ho s t : t e s t . g i t

12 / 27

Overview

IntroductionIn a world without versioncontrolTypes of version controlThis is git

Getting startedPreparationsYour own repositoryFirst time with a repositoryConnect more users

Using git

Everyday useTagsBranchingUndoA closer look at the historyIgnoring filesGit on Windows

ConclusionSummaryBibliography and linksQuestions and comments

13 / 27

Everyday use

Which commands to you actually need to learn?

add Mark file for saving.

reset Unmark file for saving.

commit Save changes to the log.

status How does the git-repo look? What files have beenchanged?

push Send all committed changes to the shared repository.

pull Download all changes from the shared repository.

checkout Get an old version of a file.

log Show a log over all commits made.

help Show the help for a certain command.

14 / 27

How is data stored in git?

Remote Repository

Local Repository

Staging Area

Working Directory

pull

fetch push

checkout add

commit

15 / 27

Demonstration

Demonstration of the basic concepts.

I Change files.

I Commit.

I Handle conflicts.

I Look in the log.

16 / 27

Tags

What is a tag?

I A named bookmark that points to a specific commit.

Commands to handle tags:

1 g i t tag <name>2 g i t tag3 g i t push −−t ag s

17 / 27

Branches and commits

1

4

3

5

7

2

6

8

masterdevel next-gen

1.0

1.1

18 / 27

How to use branches

Commands:

branch List or create a new branch. (-r to list remotebranches.)

checkout Is used to change branches.

merge Bring in changes from another branch.

Branches are local by default:

1 # Upload and f o l l o w :2 g i t push −u o r i g i n <branch>34 # Fol low a remote branch :5 g i t branch < l o c a l b r a n c h> <remote branch>

19 / 27

Undo

Undo can mean different things:

1 # While s t i l l cod ing :2 g i t checkout < f i l e >3 g i t checkout 502 f cb1 < f i l e >45 # Prepared f o r a commit , but not y e t committed :6 g i t r e s e t HEAD < f i l e >78 # Al r eady committed :9 g i t r e v e r t 502 f cb1

Leave your committed errors in the history!

20 / 27

A closer look at the history

Different ways of looking at the history:

log Show a log of all commits with their comments.

show Show details for a specific commit.

diff Compare different versions of files.

blame Show who last touched a certain row.

21 / 27

Ignoring files

How do you get git to stop listing certain files?

I Create a .gitignore file and list what should be ignored(wildcards are available.)

22 / 27

Git on Windows

What if I use Windows?

I msysgit (installs a shell and works just like on Linux.)

I Git Extensions (a GUI-application.)

I Built into your IDE (Eclipse, IntelliJ Idea, etc.)

I There are GUI programs for other operating systems also.

23 / 27

Overview

IntroductionIn a world without versioncontrolTypes of version controlThis is git

Getting startedPreparationsYour own repositoryFirst time with a repositoryConnect more users

Using git

Everyday useTagsBranchingUndoA closer look at the historyIgnoring filesGit on Windows

ConclusionSummaryBibliography and linksQuestions and comments

24 / 27

Summary

We have seen:

I What you need version control for.

I What git is.

I How to use git.

I Some of the most common problems you can encounter.

25 / 27

Bibliography and links

Guides:

I http://schacon.github.com/git/gittutorial.html

I http://ricroberts.com/articles/

getting-to-grips-with-git-part-1-the-basics

Online hosting:

I http://buck.ludd.ltu.se

I http://gitlab.com

I http://github.com

I http://bitbucket.org

More information:

I http://en.wikipedia.org/wiki/Revision_control

I http://en.wikipedia.org/wiki/Git_(software)26 / 27

Questions and comments

?

27 / 27