22

I have a local repo with 2 branches master and develop.

  • in develop branch I have all my Drupal 8 core code
  • in my master branch I have 1 commit (Initial commit)

On my remote repo I have all my Drupal 8 core code in branch develop. How do I get this code in the remote master branch? How do I have to merge those repo's?

Update:

When I do git status I get:

On branch master
Your branch is up-to-date with 'origin/master'.
Untracked files:
  (use "git add <file>..." to include in what will be committed)

    griffioenrotterdam.sublime-project
    griffioenrotterdam.sublime-workspace
    sites/

nothing added to commit but untracked files present (use "git add" to track)

What do I have to do?

Update 2:

When I do git checkout develop I get:

error: The following untracked working tree files would be overwritten by checkout:
    sites/default/default.services.yml
    sites/default/default.settings.php
Please move or remove them before you can switch branches.
Aborting

What do I have to do?

Yves M.
  • 29,855
  • 23
  • 108
  • 144
meez
  • 3,783
  • 5
  • 37
  • 91
  • Do you want to save / track the above files before? or you don't care about them? – ItayB Apr 12 '16 at 10:29
  • The first 2 I don't care and they are ignored by my .gitignore file. But `sites/` I don't understand because behind `sites/` folder there are files I want to have in the repository? What means `sites/` is popping up? And I update my question again.. – meez Apr 12 '16 at 10:37
  • first, the 2 upper files are not in your current .gitignore or might defined wrong - otherwise they shouldn't appear in the 'git status' - this is the idea of .gitignore – ItayB Apr 12 '16 at 10:40
  • About the second folder. You see the entire folder because you didn't add it's files to any commit. When all the directory is untracked it's doesn't specify each file.. you need these files or do you want to get them from the 'develop' branch? – ItayB Apr 12 '16 at 10:42
  • About .gitignore. You are wright. I have to rename them. But currently I can't get into my develop branch and edit this file? – meez Apr 12 '16 at 10:45
  • You can, but before switching branches you have to decide what to do with the uncommitted code.. if you want to discard try to add -f to 'git checkout ..' but be careful! backup your code first! – ItayB Apr 12 '16 at 10:47
  • Which uncommitted code? I am a bit lost. What do I have to do in your opinion? – meez Apr 12 '16 at 10:54
  • Possible duplicate of [Merge development branch with master](http://stackoverflow.com/questions/14168677/merge-development-branch-with-master) – Yves M. Nov 22 '16 at 09:10

4 Answers4

43

Summary: you need to switch to your develop branch, pull the code from the remote repo, then merge it into master (locally) and push it back to remote repo (into master branch)

git checkout develop
git pull origin develop
git checkout master
git merge develop
git push origin master
ItayB
  • 10,377
  • 9
  • 50
  • 77
  • I can't `git checkout develop` because I get above error (updated question 2) – meez Apr 12 '16 at 10:40
  • @MeesFrenkelFrank I add comment below your question.. BTW if you don't need these changes try 'git checkout -f develop' to force – ItayB Apr 12 '16 at 10:45
  • I have the feeling I have to clear things up. Basically what I want is: **1)** Currently when my client is looking in the remote he doesn't see anything because it's on my own branch `develop`. How do I get this into `master` branch? **2** Locally I want to add modules and themes on my `develop` branch. What is best workflow, after I have tested them locally: do I have to merge `develop` into `master` and the push to remote? How do I get them into remote master branch so my client can see the code? – meez Apr 12 '16 at 10:52
  • @MeesFrenkelFrank I got it. it's exactly what I'm trying to help you to do. The only problem is that you have to decide what to do with the current uncommitted changes in your local master branch. Your options are: 1. backup the all folder in some other place in your disk and move the sites directory from your local repository. make sure that 'git status' shows clean repo. 2. 'git add *' and 'git commit -m "bla"' (commit the sites files) and then again 'git status' should show clean repo. then do the command above – ItayB Apr 12 '16 at 11:01
  • sorry if I go for option 1) what do you mean with the all folder, the whole local master repo folder? – meez Apr 12 '16 at 11:09
  • just go to your root folder (of the all project) and backup it somewhere else on your disk - just to make sure that if something went wrong you will have another backup ;-) – ItayB Apr 12 '16 at 11:11
  • And if I go for option 2: I add also the sublime files. But after I can change my .gitignore and rename those, so they aren't tracked anymore, is that correct? – meez Apr 12 '16 at 11:18
  • yes. but then you need to commit your .gitignore file because it is modified.. so do 'git add .gitignore' and then 'git commit -m "gitignore"' – ItayB Apr 12 '16 at 11:23
  • The idea is that your repo should be clean (git status) before performing any checkout/merge/pull/push operations. – ItayB Apr 12 '16 at 11:27
  • ok. When I do `git add *` and I do `git status`, there are all `twig` files popping up from `sites/my-second-site/files/php/twig/`. Do I have to commit those? Locally i have setup a Drupal 8 multisite. – meez Apr 12 '16 at 11:34
  • Do you want them to be tracked? if the answer is yes and you see them green - you can commit – ItayB Apr 12 '16 at 11:40
  • I don't know? I don't know what they are exactly? I just want a good clean remote (central) master repo from which WE can make (clone) instances for STAGE and LIVE environments. – meez Apr 12 '16 at 11:46
  • So.. As i said before just move the sites folder to somewhere else in your file system, so you will be clean, and if you want later on we will return it to the original place.. – ItayB Apr 12 '16 at 11:51
  • I think they don't have to be tracked... But if i track them now. I commit them now. Are they later ignored by the .gitignore from develop? Because after I setup my multisites and commit those folders and tracked files they where not committed to the `develop` branch on the remote repo... – meez Apr 12 '16 at 11:54
  • Just move the sites directory outside of the project for now, so we could move to the next step! – ItayB Apr 12 '16 at 11:56
  • ok i moved the dir and deleted the files. Now its clean. So now I do: `git checkout develop git pull origin develop git checkout master git merge develop git push origin master` – meez Apr 12 '16 at 12:00
  • Yes. did it work? if so, I'll appreciate if you can accept my answer and upvote so I'll get my reputation ;-) – ItayB Apr 12 '16 at 12:18
  • I use SourceTree. I want to try to do it from SourceTree. This step `git merge develop`: In SourceTree I click on Merge > then I have the option Merge from log or Merge Fetched? What do you think? – meez Apr 12 '16 at 12:25
  • I'm not familiar with SourceTree, but it might be another new question.. try to finish these steps from the command line please – ItayB Apr 12 '16 at 12:31
  • So to make things clear. Locally I continue working in my develop branch. I commit those changes. Whats not clear to me. Do I have to push them to remote master or remote develop. What sense make my develop branch on remote? Or do I always have to merge my develop into master locally and then push to remote master? Because [this article](https://www.drupal.org/node/803746) the have a different approach or not? – meez Apr 12 '16 at 12:43
  • I can't read the article now, but there are a lot of way to use git. I would recommend to work on your local develop branch for while developing and push it into your remote develop for backups (let say, if you in a middle of a work but you want to make sure that your computer won't burn up. Just when you are done with the work and you want to merge it to the "main" branch - your master - then merge your develop branch into it (your local master of course) and push your local master into your remote master - again - for backup (or for sharing it with other people). – ItayB Apr 12 '16 at 12:52
  • 2
    absolute life saver – Izac Mac Nov 24 '17 at 02:28
  • What if master is a protected branch that you are not allowed to push to? We only merge to master from development on github. – Monroe Mann Apr 15 '21 at 14:24
  • 1
    If you're on github, push your changes to the development branch and create a pull request to merge your development branch into master – ItayB Apr 15 '21 at 16:01
7

Merge locally develop into master and then push

git checkout master
git merge develop
git push
Francesco
  • 4,052
  • 2
  • 21
  • 29
  • Thanks. i will try that. But when I do `git status` I get above in Updated question. What do I have to do? – meez Apr 12 '16 at 10:28
  • What if master is a protected branch that you are not allowed to push to? – Monroe Mann Apr 15 '21 at 14:23
  • 1
    Protected branch only exists in wrappers like gitlab/github. In such case I believe you should push to develop and create a pull request to master – Francesco Apr 20 '21 at 16:10
1

First commit your changes to master

 git checkout develop
 git pull origin develop
 git checkout master
 git merge develop
 git push origin master
Francesco
  • 4,052
  • 2
  • 21
  • 29
0

I would think the process is to use git pull request to merge from dev(remote) to master(remote).

Feng Zhang
  • 1,698
  • 1
  • 17
  • 20