# Need help with Git



## urello (Jul 25, 2013)

Hi there.

I want to set up a primary bare Git repository and two local repositories which will occasionally push data into the primary repository. 

I did the following on the primary server called githost:

```
[/dev/pts/1]termit@githost:~> mkdir gitdir 
[/dev/pts/1]termit@githost:~> cd gitdir/ 
[/dev/pts/1]termit@githost:~/gitdir> echo "bla" > file1; echo "blabla" > file2; echo "testbla" > file3 
[/dev/pts/1]termit@githost:~/gitdir> ls 
total 6 
-rw-r--r--  1 termit  wheel  -    4B Jul 25 11:20 file1 
-rw-r--r--  1 termit  wheel  -    7B Jul 25 11:20 file2 
-rw-r--r--  1 termit  wheel  -    8B Jul 25 11:20 file3 
[/dev/pts/1]termit@githost:~/gitdir> git --bare init 
Initialized empty Git repository in /usr/home/termit/gitdir/
```
On the local server called taz-x10:

```
[termit@taz-x10 ~]$ git clone ssh://githost:1122/usr/home/termit/gitdir 
Cloning into 'gitdir'... 
Password: 
warning: You appear to have cloned an empty repository. 
Checking connectivity... done
```
The repository is empty. Why? Then I tried to push files into the bare repository from the local repository:

```
[/dev/pts/2]termit@taz-x10:~> mkdir gitdir 
[/dev/pts/2]termit@taz-x10:~> cd gitdir/ 
[/dev/pts/2]termit@taz-x10:~/gitdir> echo "bla" > file1; echo "blabla" > file2; echo "testbla" > file3 
[/dev/pts/2]termit@taz-x10:~/gitdir> git init 
Initialized empty Git repository in /usr/home/termit/gitdir/.git/ 
[/dev/pts/2]termit@taz-x10:~/gitdir> git add file1 file2 file3 
[/dev/pts/2]termit@taz-x10:~/gitdir> git config --global user.email "you@example.com" 
[/dev/pts/2]termit@taz-x10:~/gitdir>  git config --global user.name "Your Name" 
[/dev/pts/2]termit@taz-x10:~/gitdir> git commit -m "test" 
[master (root-commit) e99673a] test 
 3 files changed, 3 insertions(+) 
 create mode 100644 file1 
 create mode 100644 file2 
 create mode 100644 file3 
[/dev/pts/2]termit@taz-x10:~/gitdir> git push ssh://githost:1122/usr/home/termit/gitdir 
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 

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) 

Password: 
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 'ssh://githost:1122/usr/home/termit/gitdir'
```
What am I doing wrong?


----------



## gqgunhed (Jul 26, 2013)

Hi @urello,

I suggest following the excellent guide at Getting-Started-First-Time-Git-Setup and the following chapters.

As far as I know, `git --bare init` is used to initialize a central (aka server) repository. I will not use the files therein, as long as they are not pushed to there from the outside (aka client). So this command creates a central point to talk to from different clients. Nothing more. The files "file[123]" will only be used when pushed to the server, not when put therein manually.

Next step is to clone the repository to a client. So the command `git clone [url=ssh://githost:1122/usr/home/termit/gitdir]ssh://githost:1122/usr/home/termit/gitdir[/url]` is correct and creates an empty repository. Now put your files "file[123]" into your working copy located at [termit@taz-x10 ~/gitdir]$. To check if your working copy has recognized the remote repository use the command `git remote -v`. It should show you something about "remote master origin" (sorry, don't have the exact message at the moment).

So in the case you mentioned being unable to push to a repository is based on the fact that your repository doesn't know it's remote location. See `git help remote`.

So basic steps for quick'n'dirty:

set up a remote repository `git init --bare --shared`, see Getting-Git-on-a-Server
clone that repository to your working directory `git clone file:///[your filepath to the repo from above goes here]`
now the working repository should give a reasonable output when asked with `git remote -v`.
create/change your files as intended
push your files with just a simple `git push` (the remote location is set during the clone phase).

Hope this helps.


----------



## kpa (Jul 26, 2013)

There is no "central" repository in GIT. Every repository is local in a sense and all copies of the repository are no less or more central than the original. All checked out copies of the repository can be used for sharing, this is in stark contrast with SVN where a checkout can not be used to share the repository further.


----------



## urello (Jul 29, 2013)

Thank you @gqgunhed! Your post was very useful for me.


----------

