I have currently one of the project it contain more branches. master branch not yet merger long time. So i want switched to master with latest code.
Can you please g
If you want to have in master exactly the same files state as in other_branch and save history - do the following (and note the period at the end):
git checkout master
git checkout other_branch .
Now you will have a full copy of other_branch in current master (it is softer than reset
), not yet committed. Then make a regular commit:
git add --all
git commit -m "* copy other_branch to master working tree"
Note: untracked (unindexed) files (directories) from other_branch will remain, if they are not tracked by master. To remove those untracked files (directories):
git clean -fd
See How to remove local (untracked) files from the current Git working tree? for more details.
you need to merge your current branch into the master branch. the way i do it is:
1) git fetch origin # get all branches from server
2) git rebase master # update your local master to the origin master, in case master has changed upstream
3) git checkout <branch> # go to your branch
4) git rebase master # rebase your branch to master; applies your branch's changes ontop of the master, where it diverged
5) git checkout master # go back to master
6) git merge <branch> # merge your branch into master. since you rebased, this should be trivial
7) git push # push your master upstream
Firstly, I would try just merging it to master
and seeing if there really are lots of conflicts - git's merging is great at only marking genuine conflicts. If you make sure that your git status
is clean before you start, and you find that there are too many conflicts to deal with, you can just go back with:
git reset --merge
However, if you just want to make your current master
the same as your other branch, you could do that with:
git checkout master
git reset --hard other-branch
However, that's generally a bad idea since:
git branch old-master master
beforehand.)master
branch, so if you've ever shared this branch with anyone the results will be confusing for both of you.git reset --hard
should always be used with caution, since it will throw away all uncommitted changes you have.If you want to merge the working branch into the master, you can also use rebase which is a bit cleaner.
git checkout master
git rebase <working branch>
Maybe it's not so clean, but it works for me
If you want to copy the files from the branch to master do execute following commands.
git checkout master
git checkout branch_from_which_you_have_to_copy_the_files_to_master .
(with period)
git add --all
git push -u origin master
git commit -m "copy from branch to master"