How do i move changes from one branch to another in git?



  • git man page: http://bit.ly/2nvGNWB

    From time to time you will have changes you made in one branch that you want to merge into another branch.

    You have to be in the branch you want to merge into first, normally this will be your master branch from a feature or dev branch.

    Move to master if that's where you want to merge, this is just an example.

    $  git checkout master
    Already on 'master'
    

    Now merge (bring in the changes) from dev branch into master

    $ git merge dev
    Already up-to-date.
    

    That's what happens when there nothing to merge.

    If however you made a change in a file in dev branch, and committed it, you can see the dev branch is ahead of the master, to sync these up you need to merge as before.

    $ git log --oneline --all --decorate --graph
    * b3edd31 (dev) Remove dev line that was not required
    *   acf3a5d (HEAD, origin/master, master) Merge pull request #3 from testbeetroot54/new_puppet_feat
    |\  
    | * 5003d53 We added a new feature for puppet
    |/  
    * bca37b2 Mods for dev env
    *   5dde774 Fixed conflicts in mathup file
    ...
    
    $ git checkout master
    Switched to branch 'master'
    
    $ git merge dev
    Updating acf3a5d..b3edd31
    Fast-forward
     watch/mathup | 1 -
     1 file changed, 1 deletion(-)
    

    Now master and dev are merged, but it's our master is still ahead of the remote (Github)

    $ git log --oneline --all --decorate --graph
    * b3edd31 (HEAD, master, dev) Remove dev line that was not required
    *   acf3a5d (origin/master) Merge pull request #3 from 
    testbeetroot54/new_puppet_feature
    |\  
    | * 5003d53 We added a new feature for puppet
    |/  
    * bca37b2 Mods for dev env
    

    Let's push up our changes to the remote

    $ git push origin master
    Counting objects: 7, done.
    Delta compression using up to 4 threads.
    Compressing objects: 100% (4/4), done.
    Writing objects: 100% (4/4), 391 bytes | 0 bytes/s, done.
    Total 4 (delta 2), reused 0 (delta 0)
    remote: Resolving deltas: 100% (2/2), completed with 2 local objects.
    To [email protected]:testbeetroot54/mygitrepo.git
       acf3a5d..b3edd31  master -> master
    

    Now everything is sync'ed up properly

    $ git log --oneline --all --decorate --graph
    * b3edd31 (HEAD, origin/master, master, dev) Remove dev line that was not required
    *   acf3a5d Merge pull request #3 from testacct808/new_puppet_feature
    |\  
    | * 5003d53 We added a new feature for puppet
    |/  
    * bca37b2 Mods for dev env
    

Log in to reply
 

© Lightnetics 2024