How to find which git branch I am on when my disk is mounted on other server

GitGit Branch

Git Problem Overview


Our git repo is on a Linux server; I can be on the master branch or create a new branch that I can go inside and use.

Our git repo disk is mounted on AIX box to build (I can see git directory in the AIX box that allows me to build)

In the AIX box how I can see that I am using master or inside a particular branch. What changes inside .git that drives which branch I am on?

Git Solutions


Solution 1 - Git

git branch with no arguments displays the current branch marked with an asterisk in front of it:

user@host:~/gittest$ git branch
* master
  someotherbranch

In order to not have to type this all the time, I can recommend git prompt:

https://github.com/git/git/blob/master/contrib/completion/git-prompt.sh

> In the AIX box how I can see that I am using master or inside a particular branch. What changes inside .git that drives which branch I am on?

Git stores the HEAD in the file .git/HEAD. If you're on the master branch, it could look like this:

$ cat .git/HEAD
ref: refs/heads/master

Solution 2 - Git

Try using the command: git status

Solution 3 - Git

You can look at the HEAD pointer (stored in .git/HEAD) to see the sha1 of the currently checked-out commit, or it will be of the format ref: refs/heads/foo for example if you have a local ref foo checked out.

EDIT: If you'd like to do this from a shell, git symbolic-ref HEAD will give you the same information.

Solution 4 - Git

.git/HEAD contains the path of the current ref, the working directory is using as HEAD.

Solution 5 - Git

> Our git repo disk is mounted on AIX box to do BUILD.

It sounds like you mounted the drive on which the git repository is stored on another server, and you are asking how to modify that. If that is the case, this is a bad idea.

The build server should have its own copy of the git repository, and it will be locally managed by git on the build server. The build server's repository will be connected to the "main" git repository with a "remote", and you can issue the command git pull to update the local repository on the build server.

If you don't want to go to the trouble of setting up SSH or a gitolite server or something similar, you can use a file path as the "remote" location. So you could continue to mount the Linux server's file system on the build server, but instead of running the build out of that mounted path, clone the repository into another folder and run it from there.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser79292View Question on Stackoverflow
Solution 1 - GitralphtheninjaView Answer on Stackoverflow
Solution 2 - GitAndrew ThomasView Answer on Stackoverflow
Solution 3 - GitMatt EnrightView Answer on Stackoverflow
Solution 4 - GitpokeView Answer on Stackoverflow
Solution 5 - GitRobin DaughertyView Answer on Stackoverflow