How to determine master, origin, head
I find myself getting lost in git branches.
How can I determine what my origin/master/head is if I’m in an arbitrary git branch?
- How do I learn the process of application development by cloning an open source project from github?
- git: merge a portion of one branch's source tree into another, regardless of individual commits
- Visual Studio 2013, Git Cloning Issue
- svn repository checkout without branches
- How to ignore files on Visual Studio Team Services (not for local server)
- What's the best way to deploy multiple projects to a server with Git?
This way I can predict the effects of commands such as those shown here.
4 Solutions collect form web for “How to determine master, origin, head”
It’s not clear from your question that you entirely understand what origin, master, and HEAD refer to – only one of them is actually a branch. (And it’s HEAD, not head.) It’s quite possible some of your confusion stems from a lack of understanding of a couple core things, so it really is a good idea for you to thoroughly read a references like the Git Book (which you linked to), starting from the beginning. You might also appreciate the Git Parable, which gives a friendly, story-like description of the basic ideas of Git.
HEAD refers to the currently checked-out commit. It normally does so via a branch; HEAD points to the branch, which points to the commit – so usually we just talk about what branch is checked out. So you seem to be asking either how to determine what branch you have checked out, or what commit that branch points to. You can use
git branch to determine your current branch, and also list your other branches. If you want to know more about the commit that branch points to, you could use
git show (equivalent to
git show HEAD).
master is the default name given to the branch automatically created in a new repository. The convention (which is almost universally followed) is that the master branch is the stable branch, representing the canonical current content of the repository. This means that there is almost certainly a master branch in your repository, since you either created it or cloned it from somewhere that has a master branch. Again, it’s unclear exactly what you need, but a commonly used command is
git log master, which will show commits starting from the tip of the master branch, walking back in history. If you want to also see the changes the commits made, add the
-p option. Adding the
--decorate option will tell Git to annotate commits with any branches pointing to them (e.g. you’d see
master on the top commit). Use
--graph to see ASCII art history graph, handy for understanding merges. See the
git-log manpage for more options – there are plenty. If you prefer graphical history viewing, try
gitk master. To include all branches, including remote ones, you could use
origin is the name for the default remote. When you clone a repository, this is automatically set up for you. You can see some information about it using
git remote show origin, which will show you the URL for the repo, its HEAD, the branches on the remote, and any local branches tracking those remote branches.
you can always see what your tracking branches are doing with
git branch -r | xargs git log --decorate
--graph if you want to see how they are related with branching and merging. Refresh the tracking branches with
You could you
gitk to visualise your branch structure
You can use something like this to display your brach