Branch Merger

I have two branches, namely master and development in the GitHub repository. I do all my development in the development industry, as shown.

 git branch development git add * git commit -m "My initial commit message" git push -u origin development 

Now I want to merge all changes into development branches in master . My current approach:

 git checkout master git merge development git push -u origin master 

Please let me know if the procedure I am following is correctly followed.

+684
git git-merge
source share
15 answers

I usually like to merge master into development , so if there are any conflicts, I can resolve it in the development branch itself, and my master stays clean.

 (on branch development)$ git merge master (resolve any merge conflicts if there are any) git checkout master git merge development (there won't be any conflicts now) 

There is not much difference between the two approaches, but sometimes I noticed that I do not want to merge the branch into master , but after merging them or that there is still work before they can be merged, so I prefer to leave master untouched until the final material.

EDIT: From comments

If you want to keep track of who merged and when, you can use the --no-ff flag when merging to do this. This is usually only useful when combining development into master (last step), since you may need to merge master into development (first step) several times in your workflow and creating a node commit for them this may not be very useful.

 git merge --no-ff development 
+1051
source share

Personally, my approach is the same as yours, with a few branches and some suppression of commits when they return to the master.

One of my colleagues does not like it when you have to switch branches so often, and remains in the development branch, doing something similar to the following, executed from the development branch.

 git fetch origin master git merge master git push origin development:master 

The first line checks for any upstream commits that have been made by the wizard since the last update of his local repository.

The second pulls these changes (if any) from the wizard to development

The third translates the development branch (now fully integrated with master) to origin / master.

I may be a little mistaken in his basic workflow, but this is his main point.

+89
source share

The explanation below is for those who came here without any knowledge of the branches.

The basic logic for developing a main branch is this: you only work with other branches and use master only to merge other branches.

You start creating a new branch as follows:

1) Clone the desired repository to the root of your website:

 $ cd /var/www $ git clone git@bitbucket.org:user_name/repository_name.git 

2) Create a new branch. It will contain the latest files from your main storage branch.

 $ git branch new_branch 

3) Change the git branch to new_branch

 $ git checkout new_branch 

4) Engage in coding, commits, as usual ...

 $ git add . $ git commit -m "Initial commit" $ git push (pushes commits only to "new_branch") 

5) When the work in this branch is completed, merge it with the "main" branch:

 $ git merge master $ git checkout master (goes to master branch) $ git merge development (merges files in localhost. Master shouldnt have any commits ahead, otherwise there will be a need for pull and merging code by hands!) $ git push (pushes all "new_branch" commits to both branches - "master" and "new_branch") 

Update: I highly recommend using GitKraken for this to see the visual change tree and better see all the logic and commits.

+23
source share

It would be great if you could use the Git Flow workflow . It can easily combine a developing branch into a workshop.

What you want to do is just follow the git-flow instruction mentioned here:

STEPS:

  • set up a git-flow project
  • create branches and combine everything for development
  • run the git flow release start <version_number> command
  • then provide a meaningful release message
  • run the git flow release finish <version_number> command
  • it will merge everything into master and change the branch to master .
  • run the git push command to post the changes to the remote wizard .

For more information, visit the page - http://danielkummer.imtqy.com/git-flow-cheatsheet/

+20
source share
 1. //pull the latest changes of current development branch if any git pull (current development branch) 2. //switch to master branch git checkout master 3. //pull all the changes if any git pull 4. //Now merge development into master git merge development 5. //push the master branch git push origin master 
+14
source share

Yes, that’s correct, but it seems like a very simple workflow where you simply buffer the changes before they are ready for integration. You should learn the more complex workflows that git supports. You might like the branch section , which allows you to work with several functions in parallel, or the calibration approach , which extends your current process a bit.

+9
source share

If you are on a Mac or Ubuntu, go to the working folder of the branch. In terminal

suppose harisdev is a branchname.

 git checkout master 

if there are unsolicited or uncommitted files, you will receive an error message, and you should commit or delete all unused or uncommitted files.

 git merge harisdev git push origin master 

The last command to delete a branch.

 $ git branch -d harisdev 
+6
source share

Step 1

Create and switch to the new "dev" branch where the local git files are synchronized with the remote, but the "dev" branch does not exist yet.

 git branch dev # create git checkout dev # switch # No need to git add or git commit, the current # branch files will be cloned to the new branch by-default. git push --set-upstream origin dev # push the "dev" branch to the remote. 

Step 2

Make your changes to the "dev" branch (your current one, if you follow step 1), commit and push the remote "dev" branch.

 git add . git commit -S -m "my first commit to the dev branch" # remove the -S if you're not "secure", secure = when you already setup crypto private and public keys (ie "verified" green sign in github) git push -u origin dev # push the changes to the remote, -u origin dev is optional but good to use. 

Step 3

Merge the branch "dev" into "master".

 git checkout dev # switch to "dev" branch if you're not already. git merge master # optionally, this command is being used to resolve any conflicts if you pushed any changes to your "master" but "dev" doesn't have that commit. git checkout master # switch to "master", which is the branch you want to be merged. git merge --no-ff dev # merge the "dev" branch into the "master" one. 
+5
source share

This is how I usually do it. First, make sure you are ready to merge your changes into a wizard.

  1. Check if development matches the latest changes from your remote server using git fetch
  2. Once the selection is complete, git checkout master .
  3. Make sure the main branch has the latest updates by doing git pull
  4. After the preparation is complete, you can start the merge with git merge development
  5. Click on the changes using git push -u origin master and you're done.

You can learn more about git merging in the article.

+4
source share

1) In the development department, check the status of git with the following command:

 git status 

There should not be uncommitted code. If so, submit your code to the Development branch:

 git add * git commit -m "My initial commit message" git push origin Development 

2) In the Development branch, run the following two commands:

 git branch -f master HEAD git push -f origin master 

This will push your development branch code into the main branch.

+3
source share

Based on @Sailesh and @DavidCulp:

 (on branch development) $ git fetch origin master $ git merge FETCH_HEAD (resolve any merge conflicts if there are any) $ git checkout master $ git merge --no-ff development (there won't be any conflicts now) 

The first command will make sure that you have all the upstream commits made to the remote wizard, with a Sailesh response that won't happen.

The second will merge and create conflicts that you can then resolve.

After that, you can finally place a wizard order to switch to the wizard.

Then you merge the development branch with the local wizard. The no-ff flag will create a commit node in master to track the entire merge.

After that, you can commit and click your merge.

This procedure ensures that people see the merge commit from development to the master, and if they go to see the development branch, they will see individual commits that you made in this branch during its development.

If you wish, you can change your merge commit before sending it, if you want to add a summary of what was done in the development branch.

EDIT: my original answer suggested git merge master which did nothing, it is better to do git merge FETCH_HEAD after fetching origin / master

+2
source share

As soon as you "designed" the development branch, you ...

  git add . git commit -m "first commit" git push origin dev git merge master git checkout master git merge dev git push origin master 
+2
source share

I think the simplest solution would be

  git checkout master git remote update git merge origin/Develop -X theirs git commit -m commit -m "New release" git push --recurse-submodules=check --progress "origin" refs/heads/Master 

It also keeps a history of all branches used.

+1
source share

If you use Gerrit, the following commands work fine.

 git checkout master git merge --no-ff development 

You can save with the default commit message. Verify that the change identifier is generated. You can use the following command to make sure.

 git commit --amend 

Then click the following command.

 git push origin HEAD:refs/for/refs/heads/master 

You may encounter an error message as shown below.

 ! [remote rejected] HEAD -> refs/for/refs/heads/master (you are not allowed to upload merges) 

To solve this problem, the gerrit project administrator should create another link in gerrit named 'refs / for / refs / head / master' or 'refs / for / refs / head / *' (which will cover all branches in the future). Then grant the Push Merge Commit permission to this link and the Send permission if you want to send the GCR.

Now try the above push command and it should work.

Loans:

https://github.com/ReviewAssistant/reviewassistant/wiki/Merging-branches-in-Gerrit

stack overflow

+1
source share
 1. //push the latest changes of current development branch if any git push (current development branch) 2. //switch to master branch git checkout master 3. //pull all the changes if any from (current development branch) git pull origin (current development branch) 4. //Now merge development into master git merge development 5. //push the master branch git push origin master Error To https://github.com/rajputankit22/todos-posts.git ! [rejected] master -> master (fetch first) error: failed to push some refs to 'https://github.com/rajputankit22/todos-posts.git' hint: Updates were rejected because the remote contains work that you do hint: not have locally. This is usually caused by another repository pushing hint: to the same ref. You may want to first integrate the remote changes hint: (eg, 'git pull ...') before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details. Then Use 5. //push the master branch forcefully git push -f origin master 
-one
source share

All Articles