Yaerox
Yaerox

Reputation: 678

What does origin mean in git, and what do I misunderstand?

I just started using bitbucket and I think I got a problem understanding the structure of it.

For me, I have a new repo called ABC, I added some basic filed, commit and push origin master. Now The latest push is my origin/master, right?

Now I wanna create a branch called D and work on it. When I finished the work, I commit, and now I wanna push this logically to my master. I don't wanna push it to origin. For me it looks like I have to push everything to origin and I don't understand why. For me Origin is like a milestone, but I wanna keep the origin on the first push my basic project build.

Then I'm going to create a branch E and work on it. Finally, for me the structure should be like this.

Here a small picture hopeful to show how I think:

http://s7.postimg.org/k1f5q4b13/git_explanaition.jpg

enter image description here

Update: For those of you who understand German https://www.youtube.com/watch?v=0Im_FrvLxXo this also helped me alot understanding the system.

Upvotes: 1

Views: 1333

Answers (2)

abligh
abligh

Reputation: 25199

Your terminology is confusing. You don't push things to branches. You merge things into branches. You push to remotes.

origin is the name of your remote. In simple terms, that's a repository you have cloned from. Here's an example where there are two remotes:

amb@nimrod-ubuntu:~/git-publish/git-publish$ git remote -v show
github  [email protected]:abligh/git-publish.git (fetch)
github  [email protected]:abligh/git-publish.git (push)
origin  https://github.com/stefanha/git-publish.git (fetch)
origin  https://github.com/stefanha/git-publish.git (push)

(don't worry about the separate entries for fetch and push). You can see I cloned stefanha's github repo called git-publish, then having made some changes pushed it to my own github repo (same name).

So you merge between your local branches, and push/pull/fetch from remote repositories. A fetch fetches changes from a remote repository, and a pull (roughly) fetches then merges them into a local tracking branch. A push merges your changes to the local copy of the remote repo and pushes your changes to the remote repo.

If you create a new branch D, and have committed a change set to it, then there are two things you could do with it (well, there are probably more, but let's stick with the obvious):

  • You could merge the branch D into your local master. You might or might not then wish to push master to origin.

  • You could push D to origin, so origin now has two branches. To do this, the first time you need to tell git where to push, i.e. do git push -u origin D rather than just git push. The -u tells it to track the upstream branch, i.e. pull from there when you next do a git pull.

I've simplified a bit here, but that's basically it.

Upvotes: 4

John Zwinck
John Zwinck

Reputation: 249642

You don't "push" to master, you "merge." The "git push" command is for sending to another clone of the same repo (usually on another machine), not for moving commits between branches in the same clone of the repo.

Upvotes: 2

Related Questions