avatarEdwin Klesman

Free AI web copilot to create summaries, insights and extended knowledge, download it at here

2329

Abstract

est and most useful fact. Because in GIT, most commands are put it into the perspective of a single truth: the current branch that you’ve checked out.</p><figure id="ac13"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*eVQ7HkQ9RyF4j5ZZWHfp3g.gif"><figcaption></figcaption></figure><p id="d88d">GIT doesn’t care about that awesome feature or bug fix that you’re working on late in the evening. Not more than your fridge cares about what you stash in it, anway… It is created for the sole purpose of keeping your code safe and remember what you’ve done with it in the past.</p><p id="2641">GIT cares about two things only: what branch you’re currently working on, and what changes you’ve been applying to that branch.</p><p id="b91b">Any given moment in time, the current branch that you’ve checked out and are working on, together with any changes that you’ve applied, is the one reality for your codebase.</p><h2 id="32bb">But What’s Considered Mine?</h2><p id="eec2">That’s a fine question, dear reader. But let’s start by making sure that you get the perspective and focus that GIT has, as it will help you to better understand what GIT considers “mine”.</p><p id="856b">As far as GIT goes, it does making sure that the code that it bears and keeps safe for you is stored and archived correctly is why it is around. Keeping <i>your </i>code safe and, from the standpoint of you as a user calling it “mine” seems logical and simple.</p><p id="2c36">This also counts for things like <i>pulling</i> and <i>pushing</i> code:</p><p id="3a01">You push your <b>current</b> <b>code</b> towards the destination and pull remote code into your current local codebase.</p><p id="0fe0">Your checked out code and the changes that you applied to that are the only thing that is of interest to GIT on your machine.</p><figure id="9acb"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*2ExzH02Ev5-nI7W-KG1qwQ.gif"><figcaption></figcaption></figure><p id="b937">Mine will always be reasoned as being the code and its state in the current branch that you’re working in and the state of that code.</p><p id="68f4">For example, let’s just state you’re a nice person who likes to code and maintains the code in branch A — the same branch that you’ve checked out right now. You want to include some nifty changes f

Options

rom branch B and do this by merging that branch into branch A.</p><p id="3acf">Then branch A is considered “mine” since:</p><ul><li>you checked out branch A</li><li>this is the current singular truth for your code</li></ul><p id="ad08">If you are lucky enough you’ll have no <i>merging conflicts</i>. But if you <i>do</i> have <i>merging</i> <i>conflicts,</i> you can hopefully now see that when you get that dialog that asks you to choose between “mine”<i> </i>and “theirs” that means:</p><ul><li><b>mine: </b>your code as it was residing in branch A, just before the merge</li><li><b>theirs: </b>the code from the source, branch B, that has been taken into <i>your code </i>in the current branch A</li></ul><p id="7a47">Given this explanation, selecting “mine” will let you choose your code from branch A as the code of choice to keep after resolving the conflict.</p><p id="8036">Whereas selecting “theirs” will overwrite the code from the branch that you’re taking into the current branch and overwrites the code from branch A.</p><h2 id="36d6">Choose Wisely</h2><p id="f254">Now you know what you can consider as <i>yours</i> (mine) and <i>theirs</i>, you can decide for better or worse what code to keep when resolving the next conflict in your GIT repo.</p><p id="72fb">Make sure you only select entire files to resolve at once when you’re absolutely sure you want to keep your code or the code you’re merging <i>into your code</i> by selecting <i>theirs</i>.</p><figure id="f372"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*GCNnQGgDnRFHzTeOPS5nsg.gif"><figcaption></figcaption></figure><p id="a7d2">Whenever you’re in doubt of what was changed, it’s best to peek at a specific file and see what changes are being brought home to your current code aka <i>mine</i>.</p><h2 id="1844">To Conclude</h2><p id="92f2">The take aways that you should have gotten from this article:</p><ul><li>GIT always takes the current checked out branch and its changes as the single truth of your code base</li><li>GIT sees your current code state as “mine” and any changes that you try to merge into that as “theirs”</li></ul><p id="1a4a">Hopefully, this will save you some time next time you need to work on fixing a merge conflict on your projects in GIT.</p><p id="f53e">Code Hard, Ship Harder ✌🏻</p></article></body>

A GIT how-to for beginning and advanced developers

GIT Repos: Mine VS Theirs Explained

GIT Repos: Mine VS Theirs Explained

This post will explain without fuzz what’s the deal with that Mine VS Theirs thing when you want to resolve a conflict.

I’ve used GIT repos for over 9 years now, and there hasn’t been a year that I didn’t learn something new about working with a GIT repo. Either a better way to maintain your code versions, branches and release management, or another option for a GIT command that I didn’t know existed before.

That alone states how much power lies within the GIT cli on your machine.

Doubt On What Your GIT Tool Means?

You know that feeling when you’re working on another code merge from your branch to a central branch — like develop or test — and just aren’t sure what that message means that your tool is throwing at you this time?

I mean, we all know that a merge conflict needs some fixing. But what should you consider as “mine” within the GIT universe?

A simple search on Stack Overflow shows 500 search results on the simple question of what “mine” and “theirs” means. It might be time to show you why those words were chosen in the first place, before we dive into their meaning.

It’s All About Perspective

And that is the simplest and most useful fact. Because in GIT, most commands are put it into the perspective of a single truth: the current branch that you’ve checked out.

GIT doesn’t care about that awesome feature or bug fix that you’re working on late in the evening. Not more than your fridge cares about what you stash in it, anway… It is created for the sole purpose of keeping your code safe and remember what you’ve done with it in the past.

GIT cares about two things only: what branch you’re currently working on, and what changes you’ve been applying to that branch.

Any given moment in time, the current branch that you’ve checked out and are working on, together with any changes that you’ve applied, is the one reality for your codebase.

But What’s Considered Mine?

That’s a fine question, dear reader. But let’s start by making sure that you get the perspective and focus that GIT has, as it will help you to better understand what GIT considers “mine”.

As far as GIT goes, it does making sure that the code that it bears and keeps safe for you is stored and archived correctly is why it is around. Keeping your code safe and, from the standpoint of you as a user calling it “mine” seems logical and simple.

This also counts for things like pulling and pushing code:

You push your current code towards the destination and pull remote code into your current local codebase.

Your checked out code and the changes that you applied to that are the only thing that is of interest to GIT on your machine.

Mine will always be reasoned as being the code and its state in the current branch that you’re working in and the state of that code.

For example, let’s just state you’re a nice person who likes to code and maintains the code in branch A — the same branch that you’ve checked out right now. You want to include some nifty changes from branch B and do this by merging that branch into branch A.

Then branch A is considered “mine” since:

  • you checked out branch A
  • this is the current singular truth for your code

If you are lucky enough you’ll have no merging conflicts. But if you do have merging conflicts, you can hopefully now see that when you get that dialog that asks you to choose between “mine” and “theirs” that means:

  • mine: your code as it was residing in branch A, just before the merge
  • theirs: the code from the source, branch B, that has been taken into your code in the current branch A

Given this explanation, selecting “mine” will let you choose your code from branch A as the code of choice to keep after resolving the conflict.

Whereas selecting “theirs” will overwrite the code from the branch that you’re taking into the current branch and overwrites the code from branch A.

Choose Wisely

Now you know what you can consider as yours (mine) and theirs, you can decide for better or worse what code to keep when resolving the next conflict in your GIT repo.

Make sure you only select entire files to resolve at once when you’re absolutely sure you want to keep your code or the code you’re merging into your code by selecting theirs.

Whenever you’re in doubt of what was changed, it’s best to peek at a specific file and see what changes are being brought home to your current code aka mine.

To Conclude

The take aways that you should have gotten from this article:

  • GIT always takes the current checked out branch and its changes as the single truth of your code base
  • GIT sees your current code state as “mine” and any changes that you try to merge into that as “theirs”

Hopefully, this will save you some time next time you need to work on fixing a merge conflict on your projects in GIT.

Code Hard, Ship Harder ✌🏻

Developer
Git
Learning And Development
Developer Tools
Recommended from ReadMedium