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:

  • Merging non-git folder with git folder
  • Git: merge only the changes made on the branch
  • Merge from upstream branch to vendor branch, where vendor branch contains a subset of the upstream commits
  • How to only push to one branch in Hg?
  • Best Practice: How to handle code differences for iOS App when creating free and paid version?
  • Rename branch on github website?
  • 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

  • git: having 2 push/pull repos in sync (or 1 push/pull and 1 pull in sync)
  • Import Java project from GitHub to Eclipse
  • Bitbucket repo clone or download?
  • Trouble setting up git with my GitHub Account error: could not lock config file
  • Dynamically Fill Jenkins Choice Parameter With Git Branches In a Specified Repo
  • How To Upload Files on GitHub
  • 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:

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

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

    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
    
    Git Baby is a git and github fan, let's start git clone.