Can someone give a clear, simple way to swap the names on 2 branches with Git, with Github as remote repository?
Here's the scenario:
- I created a dev branch off master.
- After 1 commit on dev, I created branch exp (experiment).
- I checked out dev again and made 2 more commits.
- Then I realized I really wanted exp to be the branch that made those 2 commits, so I'd like to swap exp and dev
I'm fairly new at this and I've gone through some of the visual Git tutorials and searched this site and Google, but it's still not clear to me the best or intended way to fix this in Git (and particularly - with a Github remote repo)
My Bad attempts to fix this:
I've tried a few things and made a mess of it - renaming local branches with Git Extensions, but not able to get the remote Github repo to reflect that change. I tried making new branches, but can't always get those to reflect in both local and remote (regardless of where I make them).
I finally was able to get everything how I needed it with Git Extensions main pull function with "Prune remote branches", which appears to use fetch with --prune - this reflected remote deletions back to local, and also the push function with some force/delete options enabled.
I thought at first I might just be able to reset/move both branches (i.e. move exp up to dev, then reset exp back to the commit that dev was on (2 back), but when trying to reset in Git Extensions, it asks me to choose a soft, mixed, or hard reset - that made me stop and go the other route of trying to rename/create new branches, etc. Maybe this was the right track - if so, should I have done a soft or hard reset - or doesn't it matter after committing any open changes? I did a lot of searching on that, and even understanding working directory, index, and branch, it still wasn't clear in my case.
Question
There must be better ways to get this done - how can I easily swap two branches (or rename 2 branches so they effectively swap), in a way that all changes are reflected both locally and remotely (on Github)?
I would appreciate any insight on why your method is the right or easiest way to go. Thanks!
Note: I did find this question about renaming master (or any branch) - but there are a lot of steps there. I could do that twice, but I find it hard to believe that is the best way to do this.