<<

Version Control – Agile Workflow with /GitHub

19/20 November 2019 | Guido Trensch (JSC, SimLab Neuroscience) Content

Motivation

Version Control Systems (VCS)

Understanding Git

GitHub (Agile Workflow)

References

Forschungszentrum Jülich, JSC:SimLab Neuroscience 2 Content

Motivation

Version Control Systems (VCS)

Understanding Git

GitHub (Agile Workflow)

References

Forschungszentrum Jülich, JSC:SimLab Neuroscience 3 Motivation

• Version control is one aspect of configuration management (CM). The main CM processes are concerned with:

• System building

• Preparing software for releases and keeping track of system versions.

• Change management

• Keeping track of requests for changes, working out the costs and impact.

• Release management

• Preparing software for releases and keeping track of system versions.

• Version control

• Keep track of different versions of software components and allow independent development.

[Ian Sommerville,“”] Forschungszentrum Jülich, JSC:SimLab Neuroscience 4 Motivation

• Keep track of different versions of software components • Identify, store, organize and control revisions and access to it • Essential for the organization of multi-developer projects is independent development • Ensure that changes made by different developers do not interfere with each other • Provide strategies to solve conflicts

CONFLICT

Alice Bob Forschungszentrum Jülich, JSC:SimLab Neuroscience 5 Content

Motivation

Version Control Systems (VCS)

Understanding Git

GitHub (Agile Workflow)

References

Forschungszentrum Jülich, JSC:SimLab Neuroscience 6 Version Control (VCS)

There are two types of version control systems:

• Centralized systems

• Distributed systems

Forschungszentrum Jülich, JSC:SimLab Neuroscience 7 Version Control (VCS)

Centralized systems • Maintain a single master repository

(RCS, 1982) • Concurrent Versioning System (CVS, 1986) • Subversion (SVN, 2000)

[Scott Chacon and Ben Straub, “Pro Git”]

Forschungszentrum Jülich, JSC:SimLab Neuroscience 8 Version Control (VCS)

Distributed systems • Multiple versions of the component repository exist at the same time

• Git (by Linus Torwalds, 2005)

[Scott Chacon and Ben Straub, “Pro Git”]

Forschungszentrum Jülich, JSC:SimLab Neuroscience 9 “Distributed version control is essential for open- development where several people may be working simultaneously on the same system without any central coordination.”

[Ian Sommerville,“Software Engineering”]

Forschungszentrum Jülich, JSC:SimLab Neuroscience 10 Content

Motivation

Version Control Systems (VCS)

Understanding Git

GitHub (Agile Workflow)

References

Forschungszentrum Jülich, JSC:SimLab Neuroscience 11 Understanding Git

Remote Repository

clone fetch push

Local Repository

pull init Stage commit -a

checkout add

Working Directory

Forschungszentrum Jülich, JSC:SimLab Neuroscience 12 Understanding Git

Obtain a repository

• git init Create an empty Git repository or reinitialize an existing one. • git clone Clone a repository into a new directory.

Example: git clone https://github.com/gtrensch/SoftwareDevInScience2019.git

Forschungszentrum Jülich, JSC:SimLab Neuroscience 13 Understanding Git

Get changes from a remote repository

• git fetch Download objects and refs from another repository. • git pull Fetch from and integrate with another repository or a local branch. (shorthand for git fetch followed by git FETCH_HEAD)

Forschungszentrum Jülich, JSC:SimLab Neuroscience 14 Understanding Git

Push changes to a remote repository

• git add Add file contents to the index (stage). • git commit -m Record changes to the repository. • git push Update remote refs along with associated objects.

Forschungszentrum Jülich, JSC:SimLab Neuroscience 15 Understanding Git

Branching

• git checkout –b • git branch – Both commands creates a new branch. • git branch –d Deletes a branch. t origin / master

branch Commits waiting for review and merge into master.

Forschungszentrum Jülich, JSC:SimLab Neuroscience 16 t origin / master Don‘t work on your master!

branch

Forschungszentrum Jülich, JSC:SimLab Neuroscience 17 Understanding Git

Useful Git commands

• git status Show the working tree status. • git reset Reset current HEAD to the specified state. • git Show changes between commits, commit and working tree, etc. • git merge Join two or more development histories together. • git remote Manage set of tracked repositories. Forschungszentrum Jülich, JSC:SimLab Neuroscience 18 Content

Motivation

Version Control Systems (VCS)

Understanding Git

GitHub (Agile Workflow)

References

Forschungszentrum Jülich, JSC:SimLab Neuroscience 19 GitHub (Agile Workflow)

What is GitHub? • Web-based Git repository hosting service • Platform to share open-source projects www..com • ~ 5 million registered developer accounts • ~10 million hosted projects • Supports agile practices:

• Code review workflow • and Delivery (CI/CD) • Coupling with Travis CI • Basic project management

Forschungszentrum Jülich, JSC:SimLab Neuroscience 20 GitHub (Agile Workflow)

• Issue tracker • • GitHub ”forking”: • Enables you to copy a repository from one user‘s account. • You can make changes under your own account and share your work by and issue a so called ”pull request”.

Forschungszentrum Jülich, JSC:SimLab Neuroscience 21 GitHub (Agile Workflow)

Fork

Forschungszentrum Jülich, JSC:SimLab Neuroscience 22 GitHub (Agile Workflow)

GitHub – Git – Workflow • Not rules, but guidelines developers can follow. GitHub UPSTREAM ORIGIN fork Project Repository 1 My Project Repository pull request Master Branch 5 Branch Master

6 merge 2 git push origin 4 git clone

Local git branch -c Master 3 Branch

My Working Directory

Forschungszentrum Jülich, JSC:SimLab Neuroscience 23 GitHub (Agile Workflow)

GitHub – Git – Workflow • Actualize the Master GitHub UPSTREAM ORIGIN Project Repository My Project Repository

Master Branch Master

1 git pull upstream master 2 git push origin master

Local Master Branch

My Working Directory

Forschungszentrum Jülich, JSC:SimLab Neuroscience 24 GitHub (Agile Workflow)

GitHub – Git – Workflow • Collaborate GitHub UPSTREAM ORIGIN ORIGIN Project Repository Project Repository Project Repository

Master Master Master

Branch A 3 Branch A pull request pull request merge 2 4 merge Branch B 1 Branch B

Local Master Branch A Master Branch B

Project Repository Project Repository

Forschungszentrum Jülich, JSC:SimLab Neuroscience 25 GitHub (Agile Workflow)

GitHub – Git – Workflow • Feature Branch GitHub UPSTREAM ORIGIN Project Repository Project Repository

Master Feature Branch Master Feature Branch merge merge pull request Branch Branch

Local git branch -c Master Feature Branch Branch

Project Repository

Forschungszentrum Jülich, JSC:SimLab Neuroscience 26 Content

Motivation

Version Control Systems (VCS)

Understanding Git

GitHub (Agile Workflow)

References

Forschungszentrum Jülich, JSC:SimLab Neuroscience 27 References

• Everything you need to know about Git.

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

• Git Reference

https://git-scm.com/docs

• GitLab

https://about.gitlab.com/

Forschungszentrum Jülich, JSC:SimLab Neuroscience 28