Pradeep K. Pant Blog

 

git quick tip – branching and merging

Sometimes you want to do experiment work or wants to patch the git master branch with some experimental code, in that case, it’s not the good idea to change the local master branch. Below are steps to do the changes in an experimental branch made with master and merge back to master and the pushback server.

Scenario:

    • Create a new branch locally with the existing branch
    • Make changes and commit these changes
    • Merge them with the local branch from where we have made the branch
    • push to the git server.
  • **Example:
    ** # Make a master_dev from master branch
    $ git checkout -b master_dev master<br />
    # Do changes in master_dev branch
    $ git commit -am "Commit message"

    # Checkout master branch
    $ git checkout master

    # Merge the changes of master_dev to master
    $ git merge --no-ff master_dev

    # Push the changes of master to origin master
    $ git push origin master

    # Optionally one can push the master_dev branch to remote
    # DO ONLY IF YOU WANT MASTER_DEV BRANCH ALSO ON SERVER
    $ git push origin master_dev

     

    Happy programming!

    ``



     

     

    Copyright © 2007-2024 PRADEEP K. PANT

    Source Code | RSS