“Moving a branch” may mean two things:

1. Move the contents (the commits, the changes) associated with branch A somewhere else in the repository.

2. Move the branch name (not the code changes!) to point to some other commit.

Let’s examine the two possibilities in detail:

1. Move branch contents and name:

This case is more complicated. If that’s what you want to do then “git rebase” is your friend. This command is quite complex and I suggest you study the git rebase help page before using it (‘git help rebase’).

 

Just to give you a quick example:

If your tree looks like this:

---o---o---o---o master
    \
      o---o---o---o---o next
                        \
                          o---o---o topic

And you want to move topic (all 3 commits associated with this branch) to master, then this command will do it:

git rebase --onto master next topic

This basically means “put onto ‘master’ everything between ‘next’ (not inclusive) and ‘topic’ (inclusive)”

After doing this your tree will look like this:


---o---o---o---o master
   |            \
   |              o´--o´--o´ topic
    \
      o---o---o---o---o next

2. Move just branch name

To do this do type:
git pull  .  +db_shdw_modify:master
What the above wiull do is within our local repository (the .)  move the branch master (just the branch name, not the contents) to the same location as branch db_shdw_modify. In other words after this command both will point to the same commit.

Tagged with:
 

One Response to How to move a branch in git?

  1. lunette de soleil pas cher…

    Very great post. I simply stumbled upon your blog and wanted to mention that I’ve really loved browsing your blog posts. After all I’ll be subscribing in your feed and I am hoping you write again soon!…

Leave a Reply

Your email address will not be published. Required fields are marked *

Set your Twitter account name in your settings to use the TwitterBar Section.