Giter Site home page Giter Site logo

git-conflict-resolution's Introduction

Git conflict resolution

Resolving conflicts in Git looks difficult and scary at first, but it's absolutely essential to working in a team. In this repo, you'll find demos and exercises for becoming more comfortable with conflict resolution.

Usage

Run the create-playground.sh shell script to create a playground. Go to the directory /tmp/playground/exercises/ for the exercises.

Usual workflow

A very common workflow is this:

  1. You want to create a new feature, fix a bug, etc.

  2. You update your working copy of the project:

$ git checkout master
$ git pull --rebase
  1. You create a branch for your work:
$ git checkout -b my-new-feature
  1. Every once in a while, you ensure that you are not too far off from master. This is important and conflicts can happen here.
$ git checkout master         # Back to master
$ git pull --rebase           # Pull changes from GitHub
$ git checkout my-new-feature # Go back to your own branch
$ git rebase master           # Try to replay your changes on top of the new master

Useful commands

Here are commands that are useful when you are dealing with a conflict.

  • git rebase --abort: if things have gone wrong, you can always abort a rebase with this command. You'll still have to deal with the conflict, but this is a nice “restart” feature.

  • git merge --abort: the same as above, but when you want to abort a merge operation.

  • git diff myfile: when a conflict occurs, this will show you where the conflict markers (the <<<<<, =====, and >>>>>) are.

  • git add myfile: after you've dealt with the conflicts in myfile, this will mark myfile as resolved.

  • git rebase --continue: after you've fixed all conflicts and marked all the files as resolved, this will continue the rebase.

Some general tips

“An ounce of prevention is worth a pound of cure,” as the saying goes. Here are some tips that can help prevent the difficulty of resolving conflicts.

  1. Keep your branches small: small branches touch fewer files and are live for a shorter period of time. This reduces the chances that someone else will introduce changes that will conflict with yours.

  2. Rebase often: Regularly rebase against the master branch (or the branch you forked off of). It's easier and faster to fix a few small conflicts than to fix one large conflict.

  3. Talk to your teammates: It's easier to manage conflicts if you know that large changes are coming than if they appear completely unexpected.

git-conflict-resolution's People

Contributors

gnuvince avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.