0% found this document useful (0 votes)
9 views50 pages

Week3 Git

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1/ 50

Software Engineering

Week 3
Software Engineering
Wk Lecture Practical
1 Introduction Canvas, Assessment Understand the case study.
Software lifecycle Write the user stories.
Design the database and the
2 Work as a group! Agile
software
Plan the work on the UI Review of the OOP concepts.
Set the version control
and the Use Case diagram.

3 User Stories Git

4 Graphical User Interface. Redgate - Guest Lecture Coding


MVC design pattern. Retrospective
Check if you are on track.
5 Plan the work on the From UML to C# code
database Create and connect the database to the
application.
6 Plan the current task Unit testing
7 -9 Retrospective. Design patterns More coding.
Plan the current task. Accomplish the quality.
Secure coding.
10 Software Validation and Verification Double check.
No new features.
Software Maintenance. Enhancements.
11 Software Management.
12 Review Presentation
How do you keep track of the changes made to a file / program?

How do you back up your software applications?

What do you do when you want to get rid of a piece of code written
a while ago.

Version Control or Source Control


Version Control or Source Control

“Version control is a system that records changes to a file or set of


files over time so that you can recall specific versions later.”

Chacon, S., Straub B., ProGIt, APress


Version Control or Source Control

Version control systems:

1.Local Version Control Systems (RCS)


2.Centralised Version Control Systems (CVS, Subversion,
Perforce)

3.Distributed Version Control Systems (Git, Mercurial, Bazaar,


Darcs).
GIT

Git stores snapshots of what the files submitted look like.

Chacon, S., Straub B., ProGIt, APress


GIT

There are 3 states in GIT the files can be in:


•Committed
– the files are changed and stored in the database (commit done)
•Modified
– the files are changed but not stored in the database (no commit
done)
•Staged
- the files are marked to go into the next commit
GIT

To accommodate the 3 states, Git projects has 3 sections:


•the Git directory
•the working directory
•the staging area

Chacon, S., Straub B., ProGIt, APress


GIT
The Git directory – Git stores there the metadata and the version database for the project (submitted).

Do not confuse the version database used by Git to store the project with
the database used inside the project!

Chacon, S., Straub B., ProGIt, APress


GIT

The working directory – contains one version of the project


checked out from the version database. The files in the working
directory can be used and modified.

The staging area – is a file that stores information about what will
go into the next commit.

Chacon, S., Straub B., ProGIt, APress


Installing Git

Chacon, S., Straub B., ProGIt, 2nd edition, Apress


Pp 36 – 42
Basic actions in Git

For details please read chapter 2 of ProGit book.


Track an existing project

Version-control an exiting project or just some files.

$ git init
Clone an existing project

Get a copy of an exiting Git repository

$ git clone URI


Add files to the repository

To add files to the repository

$ git add files

The command add is used to:

- add a new file to the repository or

- stage a modified file

(plus other things)


Ignore files

Certain files should not be added to the repository.

The files to be ignored are listed in .gitignore file.

Example:
# ignore the .cache files
*.cache
# ignore the .resources files
*.resources
Commit the changes

$ git commit

All the staged files are added (checked in) to the repository.
Commit the changes

Example:

modify file1.cs // add lines 20-27

$ git add file1.cs

modify file1.cs // add lines 30-40

$ git commit

The lines 30-40 are not in the file1.cs that is in the repository
Commit the changes

Why is staging important?


Commit the changes

$ git commit -a

All the files are staged before they are committed to the repository.

It is equivalent to:
$ git add
$ git commit
See the changes done to the files

$ git status

git status displays which files are in which state.

It’s good to check what files are:

- in the stage area


- untracked
- modified but not staged
See the changes done to the files

$ git diff

git diff displays the changes done to every file.


Remove files from the repository

git rm removes the specified file from the staged area.

$ git rm file

git rm --cache removes the specified file from the staged


area.

$ git rm –cache file

To be used to remove files accidently tracked.


View the history

git log displays a list of all the commits made in the repository.

$ git log

The option -p shows the differences introduced in each commit

$ git log -p
Git - Branches

The branches are used to diverge from the main line of


development.

The development then can continue on all branches (including the


master).

A branch represents an independent line of development.


Create a branch

The master branch is created by default when

git init is executed.

43fa2

Master

Every commit goes into the master branch.


43fa1 e29ba 77ab9

Master
Create a branch

A new branch is created with:

$ git branch task1 Task1

43fa1 e29ba 77ab9

Master

Git knows what branch is current by keeping a special pointer


called Head.

The current branch is still Master!


Switch between branches

To switch between branches:

$ git checkout task1


task1

43fa1 e29ba 77ab9

Master

The current branch is task1.


Switch between branches

The new commits are done in task1.

Task1

af34c

43fa1 e29ba 77ab9

Master
Switch between branches

What does happen with the master branch?

The development can continue in parallel on the master branch.

Task1

af34c

43fa1 e29ba 77ab9

53cd2

Master
Switch between branches

When you switch between branches, the files in the working


directory change. The files of the selected branch replace the
exiting ones.

Task1

af34c

43fa1 e29ba 77ab9

53cd2

Master
Example 1

The master branch got the files: file1 and file2.


$ git branch userstory1
$ git checkout userstory1
$ git add file3
$ git add file1
$ git checkout master

Any comment?
Example 1

It’s not possible to switch between branches before having a clean


working area.
If there are uncommitted changes, Git won’t let you switch
branches.
(Check the stashing and cleaning to get around)
Merge branches

Once task 1 is finished and tested it has to be merged with the


master.
Task1

af34c

43fa1 e29ba 77ab9

Master
Merge branches

All the changes done to task 1 are committed.

$ git checkout master

$ git merge task1


Task1

af34c

43fa1 e29ba 77ab9

Master
Delete branches

The branch can be deleted if not needed anymore:

$ git branch – d task1

af34c

43fa1 e29ba 77ab9

Master
Example 2

The development continues on task1 branch. A lot of code is added


to file1.

A fix was required on the master. File1 (from master) was updated.

Task 1 is finished and can be merged with


the master. Task1

af34c e29ba

43fa1 e29ba 77ab9

53cd2

Master
Example 2

How is the merge done?


Task1

af34c e29ba

43fa1 e29ba 77ab9

53cd2

Master
Example 2

Display which files are unmerged because of the conflict.

$ git status

Resolve the conflicts manually!

Stage and then commit the files changed to finalise the merge.
Branching Workflows

Chacon, S., Straub B., ProGIt, APress


Remote Branching

The remote branches are similar to the local branches but stored on
the server and therefore accessible by the whole team.

The remote branches are used to collaborate on projects with other


developers.
Remote Branching

server

Local
computer

The git command used to clone a remote branch is:

$ git clone <remote repository>


Chacon, S., Straub B., ProGIt, APress
Remote Branching

To track just a branch of a repository:

$ git checkout <remote branch>

Chacon, S., Straub B., ProGIt, APress


Remote Branching

Commits are done to the local branch. The local and the remote
branches are unsynchronised.

server

Local
computer

Chacon, S., Straub B., ProGIt, APress


Remote Branching

To syncronise the local branch with the remote one:

$ git fetch

server

Local
computer

Chacon, S., Straub B., ProGIt, APress


Remote Branching

Chacon, S., Straub B., ProGIt, APress


Remote Branching

To syncronise the remote branch with the local one:

$ git push <remote> <local branch

server

Local
computer

Chacon, S., Straub B., ProGIt, APress


GitHub

How do you collaborate with others developers on projects?

GitHub

https://github.com/
Reading list

Chacon, S., Straub B., ProGIt, 2nd edition, Apress


https://git-scm.com/book/en/v2

Chapters 5 and 6
Questions

You might also like