Git workflows: using multiple branches for parallel development SE-2800 Dr. Mark L. Hornick 1.

Slides:



Advertisements
Similar presentations
Version Control System (Sub)Version Control (SVN).
Advertisements

Simple Git Steve Pieper. Topics Git considerations and Slicer Git as if it were svn Git the way it is meant to be.
Git Branching What is a branch?. Review: Distributed - Snapshots Files are stored by SHA-1 hash rather than filename Stored in git database in compressed.
Version Control with git. Version Control Version control is a system that records changes to a file or set of files over time so that you can recall.
1 CSE 390 “Lecture 11” Version control with Git slides created by Ruth Anderson, images from
BIT 285: ( Web) Application Programming Lecture 07 : Tuesday, January 27, 2015 Git.
Git for Version Control These slides are heavily based on slides created by Ruth Anderson for CSE 390a. Thanks, Ruth! images taken from
Git. What’s Git? A British swear A Distributed Version Control System Developed in 2005 by Linus Torvalds for use on the Linux Kernel Git Logo by Jason.
Subversion. What is Subversion? A Version Control System A successor to CVS and SourceSafe Essentially gives you a tracked, shared file system.
علیرضا فراهانی استاد درس: جعفری نژاد مهر Version Control ▪Version control is a system that records changes to a file or set of files over time so.
Introduction to Version Control
With Mercurial and Progress.   Introduction  What is version control ?  Why use version control ?  Centralised vs. Distributed  Why Mercurial ?
Created by: Maria Abrahms Modified Date: Classification: How to get it done Contributing to OpenStack.
GIT An introduction to GIT Source Control. What is GIT (1 of 2) ▪ “Git is a free and open source distributed version control system designed to handle.
Git A distributed version control system Powerpoint credited to University of PA And modified by Pepper 8-Oct-15.
Branching. Version Control - Branching A way to write code without affecting the rest of your team Merge branches to integrate your changes.
Version control Using Git Version control, using Git1.
ITEC 370 Lecture 16 Implementation. Review Questions? Design document on F, feedback tomorrow Midterm on F Implementation –Management (MMM) –Team roles.
Version Control Systems academy.zariba.com 1. Lecture Content 1.What is Software Configuration Management? 2.Version Control Systems (VCS) 3.Basic Git.
…using Git/Tortoise Git
Version Control Group Wen-hao Zeng Richard Liou. 2 Introduction Several groups develop the ITS concurrently Accumulated modification of files can cause.
SWEN 302: AGILE METHODS Roma Klapaukh & Alex Potanin.
Information Systems and Network Engineering Laboratory II DR. KEN COSH WEEK 1.
Introduction to Version Control SE-2030 Dr. Rob Hasker 1 Based on material at and slides written.
Team 708 – Hardwired Fusion Created by Nam Tran 2014.
Introduction to Version Control with Git CSC/ECE 517, Fall 2014 A joint project of the CSC/ECE 517 staff, including Titus Barik, Gaurav Tungatkar, Govind.
Intro to Git presented by Brian K. Vagnini Hosted by.
1 Web Design Workshop DIG 4104c – Lecture 5c Git: Branch and Merge J. Michael Moshell University of Central Florida giantteddy.com.
Version Control and SVN ECE 297. Why Do We Need Version Control?
Introduction to Git Yonglei Tao GVSU. Version Control Systems  Also known as Source Code Management systems  Increase your productivity by allowing.
TEAM FOUNDATION VERSION CONTROL AN OVERVIEW AND WALKTHROUGH By: Michael Mallar.
Information Systems and Network Engineering Laboratory I DR. KEN COSH WEEK 1.
Introduction to Git - Chirag Dani. Objectives Basics of Git Understanding different “Mindset of Git” Demo - Git with Visual Studio.
GIT: What, how and why ? Part 1: Basics. What do I know about git? Started using it for experiments on April 2009 Moved all voms development on git on.
Git How to 1. Why Git To resolve problems in lab exams (accidental deletions) Use existing Libraries with ease (Statistics and Computer) Prepare undergraduates.
Using Git with collaboration, code review, and code management for open source and private projects. & Using Terminal to create, and push commits to repositories.
1 Ivan Marsic Rutgers University LECTURE 2: Software Configuration Management.
BIT 285: ( Web) Application Programming Lecture 07 : Tuesday, January 27, 2015 Git.
Git A distributed version control system Powerpoint credited to University of PA And modified by Pepper 28-Jun-16.
GIT Version control. Version Control Sharing code via a centralized DB Also provides for Backtracking (going back to a previous version of code), Branching.
Source Control Dr. Scott Schaefer. Version Control Systems Allow for maintenance and archiving of multiple versions of code / other files Designed for.
CS5220 Advanced Topics in Web Programming Version Control with Git
Introduction to GitHub
Information Systems and Network Engineering Laboratory II
11 Version control (part 2)
CReSIS Git Tutorial.
LECTURE 2: Software Configuration Management
Git Practice walkthrough.
Source Control Dr. Scott Schaefer.
Version Control overview
Version control, using Git
Git branches and remotes
Software Engineering for Data Scientists
Macaualy2 Workshop Berkeley 2017
Concurrent Version Control
Distributed Version Control with git
Akshay Narayan git up to speed with RCS Akshay Narayan
Source Code Management
LECTURE 3: Software Configuration Management
BIT 286: (Web) Application Programming
The Big Picture
Version Control System - Git
Version control with Git
Git started with git: 2018 edition
GitHub 101 Using Github and Git for Source Control
Git Introduction.
Git GitHub.
Using GitHub for Papyrus Models Jessie Jewitt – OAM Technology Consulting/ ARM Inc. January 29th, 2018.
Presentation transcript:

Git workflows: using multiple branches for parallel development SE-2800 Dr. Mark L. Hornick 1

So far, you have used only a single branch (master) for synchronizing code Synchronizing frequently-changing code requires merging Merge conflicts result when the same code is simultaneously modified by >1 developer git push results in errors if someone else worked on the same code and modified/pushed it before you did. Merge conflicts can often be resolved automatically if the code modifications are sufficiently separated git pull automatically merges modifications when possible Merge conflicts sometimes need manual resolution  git pull fails to resolve the conflict, and you must manually edit the file(s) containing the conflict indicators ( >>)  git commit stages your manually-merged file(s)  git push uploads the file(s) to the remote branch SE-2800 Dr. Mark L. Hornick 2 We can reduce the amount of synchronization we need to do, as well as the number of merge conflicts, by using branches.

The master branch should only be used for maintaining production-ready code (and related files) Code modified or created during a Sprint should be maintained on separate branches A second standard branch – often named “dev” is typically used to maintain code that is being actively worked on At the beginning of a Sprint, the dev branch is identical to master During a Sprint, the dev branch maintains the evolving code At the end of a Sprint, the dev branch contains the completed code. The dev branch is then merged into the master branch, and the process repeats with the next Sprint. SE-2800 Dr. Mark L. Hornick 3 master merge branch merge Version 1 Version 2 Version 3 dev

There are two ways to create dev branch 1. Create a local dev branch and then push that branch to the remote 2. Create a remote dev branch (using the Bitbucket web interface), and then fetch that branch locally > SE-2800 Dr. Mark L. Hornick 4 $git branch dev $ > $git fetch && git checkout dev From bitbucket.org:se2800/MyRepository * [new branch] dev -> origin/dev Branch dev set up to track remote branch dev from origin. Switched to a new branch dev'

Git commands for branch status Use git branch to see what local branch you are currently working on: SE-2800 Dr. Mark L. Hornick 5 $git branch *dev master Use git fetch && git branch -r to list all remote branches: $git fetch $git branch -r origin/master origin/dev

Git commands for switching branches Use git checkout master to switch your working directory to the master branch: SE-2800 Dr. Mark L. Hornick 6 $git checkout master dev *master Use git checkout dev to switch your working directory to the dev branch: $git checkout dev *dev master NOTE: If you currently have nothing to commit, and you switch branches, the code in your working directory will be replaced with the code that is in the branch you’re switching to.

Wait! Won’t we still run into the same kind of merge conflicts if we all develop on the dev branch? SE-2800 Dr. Mark L. Hornick 7

Yes! So teams usually use additional feature and defect branches to isolate their work Additional branches – often named for the Jira story or defect, are typically used to maintain code that is being actively worked on Usually, only one person works at fixing a defect Often, different story features are worked on in parallel by only a few people on a team When a story or defect is complete (and tested), its branch is merged into the dev branch. When all stories and defects have been merged into dev, dev is merged into master SE-2800 Dr. Mark L. Hornick 8 master branch merge Version 1 Version 2 dev merge branch merge defectfix featureA branch

Switching branches during work Suppose you are working on a defectfix branch and want to switch to a dev branch with git checkout dev. You have uncommitted code on the defectfix branch, so git status reports: SE-2800 Dr. Mark L. Hornick 9 $git status On branch defectfix Your branch is up-to-date with 'origin/defectfix'. Changes not staged for commit: (use "git add..." to update what will be committed) (use "git checkout --..." to discard changes in working directory) modified: MyFile.java no changes added to commit (use "git add" and/or "git commit -a") $ git stash Saved working directory and index state WIP on defectfix : 0b5a394 HEAD is now at 0b5a394 on defectfix branch You don’t want to commit MyFile.java, because you are still working on it. If you git checkout dev at this point, you won’t get dev’s version of MyFile.java, because your working copy is still uncommitted. The solution is to stash your work first before switching branches: The git stash command saves your work to a temporary cache where it can later be recovered, and reverts the defectfix branch back to the last commit so that you can safely switch branches.

Switching back and recovering your Work In Progress (WIP) Suppose you had switched to a dev branch and now want to return to the defectfix branch to resume you work on MyFile.java. You use git checkout defectfix to switch, and that recovers the last- committed version of MyFile.java, without the changes you had been working on – those changes had been stashed away. You can use git stash list to view your stashes: SE-2800 Dr. Mark L. Hornick 10 $git stash list WIP on defectfix: 0b5a394 $ git stash pop On branch defectfix Your branch is up-to-date with defectfix '. Changes not staged for commit: (use "git add..." to update what will be committed) (use "git checkout --..." to discard changes in working directory) modified: MyFile.java no changes added to commit (use "git add" and/or "git commit -a") Dropped (dbcbe46ab23ca6f02df661bc81ac5006ffa4c60c) To recover MyFile.java use git stash pop and the working copy will be restored: Note that git stash pop clears the stash cache

Merging back into the dev branch Suppose you have finished fixing a defect on the defectfix branch You have fully tested it and verified the fix You have pushed your local work to the remote with a git push, and since you’re the only one working on the defectfix branch, you didn’t get any merge conflicts. You want to merge your defect fix into the dev branch so that it later gets merged into master. You want (need) to have your teammates review your fix and approve it before the merge can take place. You initiate a Pull Request to begin the merge process. SE-2800 Dr. Mark L. Hornick 11 master branch Version 1 dev merge branch defectfix

Executing a Pull Request From the Bitbucket web interface, click on the branches icon, hover the mouse over the line for the branch you want to merge into dev, and click on the three dots on the right. Select Create Pull Request. Enter a title and add all team members as reviewers. Leave the Close branch box checked. Note that the differences between the two branches are shown in on the Overview tab. Your teammates will get a message from Bitbucket indicating that they have code to review. They will review the differences, and either approve or decline the request. Once all have reviewed the request, you can click on the Merge button, and the defectfix branch will be merged into dev. The defectfix branch, since it is no longer needed, will be automatically deleted from the remote (since you selected Close branch above). To delete the defectfix branch from your local repository, switch to the dev branch locally, and issue the git branch –d defectfix command. SE-2800 Dr. Mark L. Hornick 12