tags:

views:

129

answers:

3

So I have 3 git branches:

  • master
  • refresh
  • auth_upgrade

I haven't really been using branches like I should...so master is way out of date, refresh is somewhat out of date and auth_upgrade is actually the branch that is completely current.

So...I ultimately want to make auth_upgrade the master branch and then git push it to my github repo.

What's the best process for doing that?

A: 

You can rename branches with the git branch -m option:

git branch -m master old_master
git branch -m auth_upgrade master
Greg Hewgill
But if I rename `auth_upgrade` to `master` and then try to push to github, I get `non-fast-forward` errors. Plus, all the new files and changes between `master` and `auth_ugrade` don't get pushed so when I deploy from the branch, the files are completely out of whack.
Shpigford
Ah, you didn't mention that `master` wasn't an ancestor of `auth_upgrade`. That does make a difference. I'll leave my answer in case it is useful for somebody else who has a similar situation that can be addressed with a rename.
Greg Hewgill
+2  A: 

You could pull auth_upgrade into master.

$ git co master
$ git pull . auth_upgrade
  • then do mainline work on master and use this branch to sync with your remote ..
  • apply the same procedure to refresh, if there are some unique changes you want to include ..

see:

$ man git-pull

    git-pull - Fetch from and merge with another repository or a local branch
The MYYN
Problem I'm running into now is that there are all sorts of conflicts with file differences between auth_upgrade and master. How can I for auth_upgrade to just overwrite any code differences in master?
Shpigford
Please look into / http://www.kernel.org/pub/software/scm/git/docs/git-merge.html // Merge strategies: ours /This resolves any number of heads, but the resulting tree of the merge is always that of the current branch head, effectively ignoring all changes from all other branches. It is meant to be used to supersede old development history of side branches.
The MYYN
A: 

If when you say 'out of date' the old branches are strict ancestors then you don't really have any merge issues.

If you just want to make your current branch into the master branch on your remote repository you can just do:

git push origin HEAD:master

Edit: from one of your comments it sounds like you don't have all of the changes from remote master in your current branch, though, so you may need to merge them in before pushing successfully:

git fetch
git merge origin/master

You can then delete you local branches. delete with a small -d is safe in that it only deletes branches that are ancestors of your current branch.

git branch -d master
git branch -d refresh.

If it bothers you that your local branch isn't called master you can now do:

git checkout -b master
git branch -d auth_upgrade
Charles Bailey