Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Git Workflows

Git Workflows

Comparison and examples of four popular Git workflows: centralized, feature branch, git flow and forking.

Avatar for Tomche Delev

Tomche Delev

March 17, 2016
Tweet

More Decks by Tomche Delev

Other Decks in Programming

Transcript

  1. Workflow The way you use and incorporate some technology in

    the daily work process. Guidelines rather than concrete rules
  2. How it works? • Central repository to serve as the

    single point-of-entry for all changes to the project (master <-> trunk) • Developers clone the central repository • Everything is stored locally isolated from the central repository
  3. John works on his feature git status # View the

    state of the repo git add <some-file> # Stage a file git commit # Commit a file</some-file>
  4. Mary works on her feature git status # View the

    state of the repo git add <some-file> # Stage a file git commit # Commit a file</some-file>
  5. Mary tries to publish her feature git push origin master

    error: failed to push some refs to '/path/to/repo.git' hint: Updates were rejected because the tip of your current branch is behind hint: its remote counterpart. Merge the remote changes (e.g. 'git pull') hint: before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details.
  6. Mary resolves a merge conflict # Unmerged paths: # (use

    "git reset HEAD <some-file>..." to unstage) # (use "git add/rm <some-file>..." as appropriate to mark resolution) # # both modified: <some-file> git add <some-file> git rebase --continue git rebase --abort
  7. Basic ideas • The core idea behind the Feature Branch

    Workflow is that all feature development should take place in a dedicated branch instead of the master branch. • Pull requests (easy way for your team to comment on each other’s work)
  8. How it works? • Still uses a central repository, and

    master still represents the official project history • Developers create a new branch every time they start work on a new feature (feature branch) ◦ animated-menu-items, issue-#1662 • Feature branches can (and should) be pushed to the central repository
  9. Pull Requests • Discuss changes before merge or ask for

    help • Once a pull request is accepted, the actual act of publishing a feature is much the same as in the Centralized Workflow
  10. Mary begins a new feature git checkout -b marys-feature master

    git status git add <some-file> git commit
  11. How it works? • The only difference… • It assigns

    very specific roles to different branches and defines how and when they should interact. • In addition to feature branches, it uses individual branches for preparing, maintaining, and recording releases
  12. Create a develop branch git branch develop git push -u

    origin develop git clone ssh://user@host/path/to/repo.git git checkout -b develop origin/develop
  13. Mary and John begin new features git checkout -b some-feature

    develop git status git add <some-file> git commit
  14. Mary finishes her feature git pull origin develop git checkout

    develop git merge some-feature git push git branch -d some-feature
  15. Mary finishes the release git checkout master git merge release-0.1

    git push git checkout develop git merge release-0.1 git push git branch -d release-0.1 git tag -a 0.1 -m "Initial public release" master git push --tags
  16. End-user discovers a bug git checkout -b issue-#001 master #

    Fix the bug git checkout master git merge issue-#001 git push git checkout develop git merge issue-#001 git push git branch -d issue-#001
  17. How it works? • fork the official repository to create

    a copy of it on the server • git clone to get a copy of it onto local machine • When ready to publish a local commit, push the commit to own public repository - not the official one • File a pull request with the main repository, which lets the project maintainer know that an update is ready to be integrated
  18. How it works? • The maintainer pulls the contributor’s changes

    into their local repository, checks to make sure it doesn’t break the project, merges it into his local master branch • Then pushes the master branch to the official repository on the server. • The contribution is now part of the project, and other developers should pull from the official repository to synchronize their local repositories
  19. Developers clone their forked repositories git clone https://[email protected]/user/repo.git git remote

    add upstream https://bitbucket.org/maintainer/repo git remote add upstream https://[email protected]/maintainer/repo.git
  20. Developers work on their features git checkout -b some-feature #

    Edit some code git commit -a -m "Add first draft of some feature" git pull upstream master
  21. The project maintainer integrates their features git fetch https://bitbucket.org/user/repo feature-branch

    # Inspect the changes git checkout master git merge FETCH_HEAD git push origin master