0

I'm trying to setup a push to deploy process over my home network. I'm trying to have a setup where I can run a process (I'll put into a bash script in time) on the server that will setup the empty repository there. Then, from my development device, I'll push to that repo on the server.

I'm working from a slightly modified version of the following tutorial. The tutorial seems to assume that the project is currently sitting on the server. I want to create the project in my development environment then have the server setup where I can then push the project to the server.

http://danbarber.me/using-git-for-deployment/

1) Here is my process I follow to setup the live repo and the bare repo on the server:

# create our app space and initialise git
mkdir /var/www/myproject && cd /var/www/myproject
git init
touch README.md
git add .
git commit -m "Setup new project"

# create bare repository
mkdir -p /var/git/myproject.git
cd /var/git/myproject.git
git init --bare
cd /var/www/myproject
git push /var/git/myproject.git master # error here too "error: src refspec master does not match any."

# configure /var/www/myproject/.git/config
cd /var/www/myproject/
git remote add hub /var/git/myproject.git

# create hook to make sure that any time anything is pushed to the hub repository it will be pulled into the live repo
# write this to /var/git/myproject.git/hooks/post-update

#!/bin/sh

echo
echo "**** Pulling changes into Live [Hub's post-update hook]"
echo

cd /var/www/myproject || exit
unset GIT_DIR
git pull hub master

exec git-update-server-info
^D

# make sure the file is executable
chmod +x /var/git/myproject.git/hooks/post-update

# create hook to make sure that any ‘in place’ changes we make to the web code is pushed to the hub when committed
# **write this to /var/www/myproject/.git/hooks/post-commit

#!/bin/sh

echo
echo "**** pushing changes to Hub [Live's post-commit hook]"
echo

git push hub
^D

# Again, ensure this file is executable.
chmod +x /var/www/myproject/.git/hooks/post-commit

2) The on my development device I do the following:

rails new myproject
cd myproject
git init
git remote add origin martyn@192.168.0.100:/var/git/myproject.git
git push origin master

..but I get the following error:

error: src refspec master does not match any.
error: failed to push some refs to 'martyn@192.168.0.100:/var/git/myproject.git'

..does anyone know what I need to do. Following the tutorial it assumes that the app already exists on the server, so it's slightly different in that it doesn't create an empty repo. But I don't want to FTP the apps files over, clone it from there then create a repo on the server. I want to create the app in development environment, run a script on the server to setup git there, then push the app from dev to my server.

Anyway this is my first time to try this, I'd appreciate any pointers or if anyone has a better suggestion to what I should be doing. Thanks

UPDATE:

I added touch README.md so that there is something to commit. Also, I added the code to setup an empty rails project and create the local repo. I get no errors on the server. But I still can't do what I want to do on my development device. When I do the following though:

cd /var/www/myproject
git clone martyn@192.168.0.100:/var/git/myproject.git myproject

I can clone down the repo from the server, then add files etc .. then push. But it's not how I want to create a new project. I want to first start building the app locally, create a local repo, .. then shortly after when I'm ready to commit, setup the server and PUSH files. Similar process to Heroku or Github, with those you don't have to clone an empty repo first from there before you can push. You can just push the files to there once their server is setup. This is similar to what I'm trying to do.

Martyn
  • 6,031
  • 12
  • 55
  • 121
  • possible duplicate of [src refspec master does not match any when pushing commits in git](http://stackoverflow.com/questions/4181861/src-refspec-master-does-not-match-any-when-pushing-commits-in-git) – Makoto May 30 '14 at 15:41

1 Answers1

0

There is no commit created on your local master branch. This will not make a commit if you don't have any files in directory:

# create our app space and initialise git
mkdir /var/www/myproject && cd /var/www/myproject
git init
git add .
git commit -m "Setup new project"
# On branch master
#
# Initial commit
#
nothing to commit (create/copy files and use "git add" to track)

Note "nothing to commit" line. git log or git show will not show you any commits. Make sure to create some files in repository directory before doing first git add.

EDIT:

Actually, technically there is no master branch in a brand new repository. This just what HEAD points to:

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

git show-ref does not show any refs. Only after the first commit master branch is created and git show-ref shows:

git show-ref
bf07c8469f5e66eff66a0a3e9c652dcc347c1de8 refs/heads/master
Arkadiusz Drabczyk
  • 11,227
  • 2
  • 25
  • 38
  • Yeh I confirmed myself that `git show-ref` doesn't show anything. I don't know if my approach is the perfect way to do what I want to do. Please see my update in original post. Can you advise on what I should be doing? Or how I can adapt my method to allow me to push? Thanks – Martyn May 30 '14 at 23:48
  • If you want to start working in your local repository without external repository and push to external repository when you are ready do this: 1. mkdir /path/to/local-repo and cd /path/to/local-repo; 2. git init; 3. make some commits; 4. mkdir /path/to/remote-repo; 5. git init --bare; 6 cd /path/to/local-repo; 7. git remote add origin /path/to/remote-repo; 8. git push -u origin master – Arkadiusz Drabczyk May 31 '14 at 00:04