Can you push a local master branch to the remote repo?


In 6. Git Workflow the directions tell you to create a local branch bio-questions and later push bio-questions to the remote.
Instead of creating bio-questions branch, can you add biology.txt to the master branch and push the local master branch to the remote, using git push origin master ?
Is it more efficient/better to push a newly created branch instead of the master branch?


If you have a local repository, then that is also a branch, because it it's branched from where you cloned it, right?

You then do some work on your branch, and push it back, they are merged.

You might want to sync the repositories without merging different branches though, so that's when you would create a branch separate from master. You might be doing some feature that isn't ready for anyone else to look at yet, but the master branch in the remote repo might have updated. They represent different things being worked on. The master branch might also be meant to always be in working order, the latest version.


Thanks for the explanation!

So it sounds like it's better not to work directly on the master branch since changes can be made in the remote, is that right? A branch separate from master would represent a new feature, so if you merge this branch to the local master, that would totally defeat the purpose of working remotely, since the other collaborator can't review this new feature.

After giving it some thought, I realized this question was kind of stupid :stuck_out_tongue:


And to actually answer the question, yes, you can push branches to another repo, names don't even need to match.

And when that feature of yours is ready, what you'd do is to make sure that it doesn't conflict with master (by merging master into your branch) and then let the owner know about it so that they can review and merge your changes into master (which is just a matter of fast-forwarding since you've already taken care of any conflicts)