Search code examples
gitgithubversion-controlpush

Git Push from release branch on the main and develop branch on Github


I'm trying to get into versioning with Git but I'm struggling a bit. If I follow good practices, I have to create several branches (main, develop, hotfix, feature and release).

When I'm on my release branch, I want to update my main branch, and the develop branch.

$ git checkout main
// Switched to branch 'main'
$ git merge --no-ff release-1.2
$ git tag -a 1.2
$ git checkout develop
// Switched to branch 'develop'
$ git merge --no-ff release-1.2
$ git branch -d release-1.2
// Deleted branch release-1.2

I don't understand how to then push the code to my remote repository and update the code on the develop and main branch.

Here the main branch is updated.

$ git push origin main

I tried this to do it on both branches but it only updated the develop branch

git push -f -u origin develop main

Is my git usage wrong and should I only update the main on the remote repository on github?


Solution

  • You want to do a lot with few, when you just start using git.

    But first, somenthing I think you do in the wrong order. You should start with develop, create a branch, make changes, merge into develop. It works?, ok, merge into release (pre-production), It works?, yes, ok, merge it into master, It works?, yes, delete the brach you create.

    Anyway, there are different flows to work with git.

    Answer your questions - Do all the steps:

    $ git checkout develop
    $ git merge --no-ff release-1.2
    $ git push -u origin develop
    

    Now you have release-1.2 changes into develop, in your local, and the remote repository.

    $ git checkout main
    $ git merge --no-ff release-1.2
    $ git tag -a 1.2
    $ git push -u origin main
    

    Now you have the changes from release-1.2 in main local, and in the remote.

    $ git branch -d release-1.2
    

    And finally you delete the branch.

    Starts with the basics, search a flow that fit your work, with the easy commands, and don't use what you don't understand. Try to do not use a cool command that can do a lot of things in one step.