From f5f6e266691a458b1dc808e40ec6a275a3457506 Mon Sep 17 00:00:00 2001
From: ramonsalguer <javier.ramon@telefonica.com>
Date: Tue, 12 Mar 2019 21:33:46 +0100
Subject: [PATCH] Procedure to move commits in master to a branch

---
 ...low for documentation production in OSM.md | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/Workflow for documentation production in OSM.md b/Workflow for documentation production in OSM.md
index 453fb46..7069c64 100644
--- a/Workflow for documentation production in OSM.md	
+++ b/Workflow for documentation production in OSM.md	
@@ -110,6 +110,25 @@ Then create a branch and move to it in order to continue. In this example, we wi
 git checkout -b BranchNewSection
 ```
 
+#### NOTE: What to do if you committed changes to master by mistake
+
+In case you forgot to create your branch (or moving to it) and made a number of commits directly to your `master` branch by mistake, you will need to use a procedure to move them to a branch, or you will be unable to work with you remote origin.
+
+To achieve it, you can still following some steps to fix your Git history and move the commits to the right place.
+
+Note that **this procedure needs to be followed exactly as it is described** or might lead to unintended loss of commits. In particular, you should understand that:
+
+- You are **rewriting** your Git history and, therefore, might delete wrong entries if you make any mistake. Please read these steps carefully and follow them accurately.
+- Any changes not committed before starting this procedure. If they are relevant for your, you should commit them (to `master`) as well.
+ 
+ As said, you can follow this procedure (assuming that you start in your `master` branch):
+
+```bash
+git branch newbranch              # Create a new branch, saving the desired commits
+git reset --hard origin/master    # Move master back to the latest commit common to the remote
+git checkout newbranch            # Go to the new branch that still has the desired commits
+```
+
 ### Step 2: Local edition and commits
 
 In this phase, you can edit your files as you would normally do.
-- 
GitLab