How to branch and merge properly with Git?
I have searched all other the web and read many instructions but it just doesn’t work and/or behave how I expected.
I was working in master and had just finished working on version 0.1 on my project and wanted to branch away from it in order to have an easily accessible snapshot of 0.1. I was currently working in master so I ran:
- How to duplicate a branch into another existing branch in git
- How to merge 2 branch in XCode?
- git fetch/merge non-fast-forward changes?
- Can I pull only certain files from another git repository?
- How to I “move” my commits from “no branch” to an actual branch?
- Update master git repository from files
git branch 0.1
This created a branch on my machine just fine but I couldn’t figure out for the life of me how to push it. I ended up running:
git config push.default current
Now I could swap between projects using:
And I was able to push them just fine and had both branches on github. I then added a log file to 0.1 which simply said “0.1 Snapshot test”, commit and pushed it fine. Then I decided I wanted that log in the master branch so I ran:
git merge 0.1
Then I pushed it. This has now kept 0.1 on my machine but has removed 0.1 from github. Edit: actually it appears it’s still on github, just hidden when looking at the overall Master page.
I guess I’m not really sure how I should be using git in order to keep track of previous but completed versions. Which order should I branch and merge in? Was this because I was working in Master that I got confused? I read through all of this but it just confused me more: http://git-scm.com/book/en/Git-Branching-Basic-Branching-and-Merging
4 Solutions collect form web for “How to branch and merge properly with Git?”
Your question is only related to pushing?
You can do this:
git push origin master git push origin 0.1 -- or all git push --all origin
Or even for all branches:
Set up git to pull and push all branches
I really like the way Git flow works. You can, of course, do all the branching, merging, and tagging steps manually, but Git flow illustrates it more clearly in my opinion:
When you create a new branch on git the first push should reference the origin:
git push origin 0.1
Hopefully I got the right end of that question.
If push doesn’t work automatically as you expect it to, you can always be explicit:
git push origin localBranchName:remoteBranchName
This pushes the local branch to the remote branch, and if there’s no such branch on the remote server, it will be created.
You can delete a remote branch with a similar syntax:
git push origin :remoteBranchName