How to create a bare repository on windows file system


mkdir GitRepoBare.git

cd GitRepoBare.git

git --bare init

cd ..

git clone ./GitRepoBare.git GitRepoClone

cd GitRepoClone

That completes the creating and cloning part. Now lets try to create some content in clone and push it to Bare.

gundlapa@MARS-ROVER ~/GitRepoClone (master)
$ cat>temp.text
asdf

gundlapa@MARS-ROVER ~/GitRepoClone (master)
$ git add *

gundlapa@MARS-ROVER ~/GitRepoClone (master)
$ git commit -m 'testing'
[master (root-commit) 7fe023c] testing
 1 file changed, 1 insertion(+)
 create mode 100644 temp.text

gundlapa@MARS-ROVER ~/GitRepoClone (master)
$ git status
On branch master
Your branch is based on 'origin/master', but the upstream is gone.
  (use "git branch --unset-upstream" to fixup)

nothing to commit, working directory clean

gundlapa@MARS-ROVER ~/GitRepoClone (master)
$ git remote -v
origin  c:/Users/gundlapa/GitRepoBare.git/ (fetch)
origin  c:/Users/gundlapa/GitRepoBare.git/ (push)

gundlapa@MARS-ROVER ~/GitRepoClone (master)
$ git push
warning: push.default is unset; its implicit value is changing in
Git 2.0 from 'matching' to 'simple'. To squelch this message
and maintain the current behavior after the default changes, use:

  git config --global push.default matching

To squelch this message and adopt the new behavior now, use:

  git config --global push.default simple

When push.default is set to 'matching', git will push local branches
to the remote branches that already exist with the same name.

In Git 2.0, Git will default to the more conservative 'simple'
behavior, which only pushes the current branch to the corresponding
remote branch that 'git pull' uses to update the current branch.

See 'git help config' and search for 'push.default' for further information.
(the 'simple' mode was introduced in Git 1.7.11. Use the similar mode
'current' instead of 'simple' if you sometimes use older versions of Git)

No refs in common and none specified; doing nothing.
Perhaps you should specify a branch such as 'master'.
fatal: The remote end hung up unexpectedly
error: failed to push some refs to 'c:/Users/gundlapa/GitRepoBare.git/'

This is where stuff breaks down. There error message on Windows isn’t clear enough. When you do a push, git tries to push the current branch (pointed by HEAD) to a branch of the same name in origin. So it is trying to push the clone’s ‘master’ branch to a ‘master’ branch in ‘origin’ remote. Do the following:

gundlapa@MARS-ROVER ~/GitRepoClone (master)
$ git push origin master:master
Counting objects: 3, done.
Writing objects: 100% (3/3), 211 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To c:/Users/gundlapa/GitRepoBare.git/
 * [new branch]      master -> master

gundlapa@MARS-ROVER ~/GitRepoClone (master)
$ git status
On branch master
Your branch is up-to-date with 'origin/master'.

nothing to commit, working directory clean

gundlapa@MARS-ROVER ~/GitRepoClone (master)
$ cat>>temp.text
Hello

gundlapa@MARS-ROVER ~/GitRepoClone (master)
$ git commit -a -m test
[master a03bb36] test
 1 file changed, 1 insertion(+)

gundlapa@MARS-ROVER ~/GitRepoClone (master)
$ git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
  (use "git push" to publish your local commits)

nothing to commit, working directory clean

gundlapa@MARS-ROVER ~/GitRepoClone (master)
$ git push
warning: push.default is unset; its implicit value is changing in
Git 2.0 from 'matching' to 'simple'. To squelch this message
and maintain the current behavior after the default changes, use:

  git config --global push.default matching

To squelch this message and adopt the new behavior now, use:

  git config --global push.default simple

When push.default is set to 'matching', git will push local branches
to the remote branches that already exist with the same name.

In Git 2.0, Git will default to the more conservative 'simple'
behavior, which only pushes the current branch to the corresponding
remote branch that 'git pull' uses to update the current branch.

See 'git help config' and search for 'push.default' for further information.
(the 'simple' mode was introduced in Git 1.7.11. Use the similar mode
'current' instead of 'simple' if you sometimes use older versions of Git)

Counting objects: 5, done.
Writing objects: 100% (3/3), 245 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To c:/Users/gundlapa/GitRepoBare.git/
   7fe023c..a03bb36  master -> master

gundlapa@MARS-ROVER ~/GitRepoClone (master)
$ git config --global push.default matching

gundlapa@MARS-ROVER ~/GitRepoClone (master)
$ git push
Everything up-to-date
Advertisements

Git: Perhaps you should specify a branch such as ‘master’.

I got this error on GitBash in Windows. This happens when you clone from a non bare repository and you are trying to push again to that.
More on that here: http://stackoverflow.com/questions/2816369/git-push-error-remote-rejected-master-master-branch-is-currently-checked

So use this instead:

git push origin master:masterOrigin

This will push your clones’s master branch to a new branch in origin called masterOrigin.

Similar error on Cygwin:

MARS-ROVER@MARS-ROVER-ST ~/SGGitClone
$ git push
Counting objects: 5, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (5/5), 512 bytes | 0 bytes/s, done.
Total 5 (delta 0), reused 0 (delta 0)
remote: error: refusing to update checked out branch: refs/heads/master
remote: error: By default, updating the current branch in a non-bare repository
remote: error: is denied, because it will make the index and work tree inconsistent
remote: error: with what you pushed, and will require 'git reset --hard' to match
remote: error: the work tree to HEAD.
remote: error:
remote: error: You can set 'receive.denyCurrentBranch' configuration variable to
remote: error: 'ignore' or 'warn' in the remote repository to allow pushing into
remote: error: its current branch; however, this is not recommended unless you
remote: error: arranged to update its work tree to match what you pushed in some
remote: error: other way.
remote: error:
remote: error: To squelch this message and still keep the default behaviour, set
remote: error: 'receive.denyCurrentBranch' configuration variable to 'refuse'.
To /home/MARS-ROVER/SGGit/.git
 ! [remote rejected] master -> master (branch is currently checked out)
error: failed to push some refs to '/home/MARS-ROVER/SGGit/.git'

MARS-ROVER@MARS-ROVER-ST ~/SGGitClone
$ git push origin master:masterOrig
Counting objects: 5, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (5/5), 512 bytes | 0 bytes/s, done.
Total 5 (delta 0), reused 0 (delta 0)
To /home/MARS-ROVER/SGGit/.git
 * [new branch]      master -> masterOrig

Git SSH agent on start

Add the following to your .bashrc file


SSH_ENV=$HOME/.ssh/environment

function start_agent {
echo "Initialising new SSH agent..."
/usr/bin/ssh-agent | sed 's/^echo/#echo/' > ${SSH_ENV}
echo succeeded
chmod 600 ${SSH_ENV}
. ${SSH_ENV} > /dev/null
/usr/bin/ssh-add;
}

# Source SSH settings, if applicable

if [ -f "${SSH_ENV}" ]; then
. ${SSH_ENV} > /dev/null
#ps ${SSH_AGENT_PID} doesn't work under cywgin
ps -ef | grep ${SSH_AGENT_PID} | grep ssh-agent$ > /dev/null || {
start_agent;
}
else
start_agent;
fi

Code formatting from http://en.support.wordpress.com/code/posting-source-code/

Git Bash .bash_profile executed twice

Not sure why this happens but this went away as soon as I created the .bash_rc file. If you know why the bash_profile executes twice, please do let me know.

Git over SSH. SSH agent issues

If you try ‘ssh-agent’ at GitBash, you will just get some script to the console, like this:

$ ssh-agent -s
SSH_AUTH_SOCK=/tmp/ssh-ZRoqi10160/agent.10160; export SSH_AUTH_SOCK;
SSH_AGENT_PID=16056; export SSH_AGENT_PID;
echo Agent pid 16056;

So you need to tell Bash to execute the output of the command by doing:

eval $(ssh-agent)

More on that here:
http://stackoverflow.com/a/21909432/1036405