Just a little confused here. When you create new branch, do you publish it right away, make changes then merge it or do you work on it locally then merge it to your local master then push local master to remote master?
Are they the same? Can you please tell me the steps?
The main benefit of git is that it is distributed source code management. You have a complete view of the source code history on your workstation.
So when you create a branch you want to commit one or many times locally.
Whether you merge to a specific branch is up to you and your project. Often projects make a development branch and work off of that, leaving master for a project lead to do the merging. You can merge a local branch to a remote branch directly, and many projects will want you to work this way. Git helps you with tools to setup your remote tracking relationship.
In fact github has engineered a review system into the flow that provides tools for people with open source projects where they want granular control over merging without giving people direct access to the shared remote repository. This is explained in illustrated fashion here.
In the simplest terms however, here's a git flow that works with any remote source where you have access to push back upstream to the remote:
git clone some-project # you are on the master branch cd some-project git checkout -b new-topic # you are in your new-topic branch # add a file touch a-new-file.txt git add a-new-file-txt git commit -m "Added a-new-file.txt" git checkout master # let's see if anything new was pushed to the remote git pull # now merge new-topic into master git merge new-topic # If there are no merge conflicts, you have a new master to smoke test # All seems well? (unit tests were run and passed, you did some testing?) git push # Lather, rinse, repeat.
The assumption (or defaulting) in this example, comes with the pull and push. Due to the fact that I push master each time, what is really happening is that my local master branch is tracking the "origin master" branch of my remote. Let's say that the lead developer wants to look at your code, and tells you to push your branch to the remote. How would you do that?
git clone some-project # you are on the master branch cd some-project git checkout -b new-topic # you are in your new-topic branch # add a file touch a-new-file.txt git add a-new-file-txt git commit -m "Added a-new-file.txt" git push -u origin new-topic # Now people can pull your branch from the remote
Note that github is a different beast and works off pull requests even though it is git under the covers.