MatthewMcGovern
MatthewMcGovern

Reputation: 3496

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:

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:

git checkout

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

Upvotes: 3

Views: 650

Answers (4)

Sergiu Dumitriu
Sergiu Dumitriu

Reputation: 11601

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

Upvotes: 1

Andreas Rehm
Andreas Rehm

Reputation: 2232

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

Upvotes: 2

Duncan Macleod
Duncan Macleod

Reputation: 1065

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.

Upvotes: 1

Jim Miller
Jim Miller

Reputation: 436

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:

http://jeffkreeftmeijer.com/2010/why-arent-you-using-git-flow/

http://nvie.com/posts/a-successful-git-branching-model/

Upvotes: 2

Related Questions