2

For one of my project, I usually need to create new branch from development branch and when I completes my work (in new-branch) I need to merge new-branch into development branch. Here is the steps I do:

 git clone –b development <git repository url>
 git branch new-branch
 git checkout new-branch
 git push --all

I do my code in new-branch and commit/push code in new-branch.

Now I need to merge new-branch into development (keep in note that development branch get further commit of other developer by the time I complete my task in new-branch). My query is what is the right approach to merge new-branch into development-branch and push it to remote repository?

Thanks

addpy
  • 1
  • 3
Nilay Anand
  • 330
  • 4
  • 17

3 Answers3

1

I prefer to put the feature branch as a squashed commit on top of develop(ment) and throw away it afterwards.

git checkout development
git merge --squash new-branch
git branch -D new-branch
git push origin :new-branch

This way you will keep a single commit containing the whole feature.

KingCrunch
  • 128,817
  • 21
  • 151
  • 173
0

If other people are pushing into 'development' then, as you've probably seen, your push might fail owing to a 'non-fast-forward' warning. Therefore the proper approach is to first pull changes from development, build and test, and then push back to development. Here would be a workflow for you:

$ git clone -b development <development repository>  <devdir>; cd <devdir>
$ git checkout -b new-branch
$ <edit, build test>
$ git add ...
$ git commit ...
# repeat above 3
#
# now you want to get your changes back on development
$ git pull origin development
$ <build, test - to ensure new-branch works w/ latest development>
$ git push origin new-branch:development
GoZoner
  • 67,920
  • 20
  • 95
  • 145
0
git checkout master
git merge dev
git commit -m 'merged branches'
addpy
  • 1
  • 3