Question

I'm working with Digital Ocean VPS, got Ubuntu Server 12.0.4 and tried to follow some instructions at Digital Ocean and went straigtforward.

However, once I push from my laptop I get this response from VPS:

Counting objects: 4, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 335 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
remote: usage: git [--version] [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
remote:            [-p|--paginate|--no-pager] [--no-replace-objects] [--bare]
remote:            [--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
remote:            [-c name=value] [--help]
remote:            <command> [<args>]
remote: 
remote: The most commonly used git commands are:
remote:    add        Add file contents to the index
remote:    bisect     Find by binary search the change that introduced a bug
remote:    branch     List, create, or delete branches
remote:    checkout   Checkout a branch or paths to the working tree
remote:    clone      Clone a repository into a new directory
remote:    commit     Record changes to the repository
remote:    diff       Show changes between commits, commit and working tree, etc
remote:    fetch      Download objects and refs from another repository
remote:    grep       Print lines matching a pattern
remote:    init       Create an empty git repository or reinitialize an existing one
remote:    log        Show commit logs
remote:    merge      Join two or more development histories together
remote:    mv         Move or rename a file, a directory, or a symlink
remote:    pull       Fetch from and merge with another repository or a local branch
remote:    push       Update remote refs along with associated objects
remote:    rebase     Forward-port local commits to the updated upstream head
remote:    reset      Reset current HEAD to the specified state
remote:    rm         Remove files from the working tree and from the index
remote:    show       Show various types of objects
remote:    status     Show the working tree status
remote:    tag        Create, list, delete or verify a tag object signed with GPG
remote: 
remote: See 'git help <command>' for more information on a specific command.
remote: hooks/post-receive: 3: hooks/post-receive: checkout: not found
To ssh://root@ip.my.vps.address/gits/cleu/cleu.git
   b21f9df..8eb93e0  master -> master

On VPS I got:

/gits/cleu.git/

And /gits/cleu.git/hooks/post-receive got as content:

#!/bin/sh
git --work-tree=/sites/node/cleu --git-dir=/gits/cleu.git
checkout -f

I also got /sites/node/cleu/ folder

On my remote machine repo folder did:

git init
git remote add live ssh://user@vpsipadress/gits/cleu.git
# Some files addition
git add .
git commit -m "Start"
git push live master

I log in by ssh to vps then and check for my pushed files and there's anything there. What are the right steps?

Was it helpful?

Solution

This statement:

And /gits/cleu.git/hooks/post-receive got as content:

Appears the indicate that cleu.git is a "bare" repository. (There's a bit of info in man git-init, but not much, really.) Typically, a git repo looks like this:

.../some-parent-dir
    .git/
        config
        description
        HEAD
        hooks
        ... and so on ...
    < your files >

A bare repository looks like this:

.../some-parent-dir.git
    config
    description
    HEAD
    hooks
    ... and so on ...

A bare repo is just a repo without a working directory. It's useful for storing the repository and it's history, but doesn't really lend itself well to working with it. You often see it on remotes where there's no point to having a working directory, because nobody ever works there.

Some hints that it's a bare repo, and not a normal one:

  • There's no .git directory.
  • Everything that would be in the .git directory is instead in the main folder.

Also, the path ends in .git, e.g., cleu.git as opposed to just cleu. This is just a common naming convention, however, so don't depend on it, but it is common to see bare repos named like that.

But where's the data?

The history is in objects. It's stored in a complicated manner; don't try to get it directly¹. Instead, just try cloning the repo:

git clone ssh://user@vpsipadress/gits/cleu.git
cd cleu
# Now take a look around.

¹Unless you'd like to learn a lot about how git works internally. It's really cool, but kinda complex. Git Internals should offer a starting place.

And about that script…

The hook script post-receive is just an executable, here, just a shell script:

#!/bin/sh
git --work-tree=/sites/node/cleu --git-dir=/gits/cleu.git
checkout -f

Note, however, that shell scripts needs commands to be on one line, like:

#!/bin/sh
git --work-tree=/sites/node/cleu --git-dir=/gits/cleu.git checkout -f

(becuase git checkout is the command here) or, alternatively, you can break this up with line continuations:

#!/bin/sh
git --work-tree=/sites/node/cleu --git-dir=/gits/cleu.git \
    checkout -f

I've indented it to more clearly denote the continuation; this is stylistic, and not strictly required, but I find it more readable. You could even:

#!/bin/sh
git \
    --work-tree=/sites/node/cleu \
    --git-dir=/gits/cleu.git \
    checkout -f
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top