Cannot find my project files on the server gitolite is running - gitolite

I cannot find my project files on the server gitolite is running.
Basically, I built a git server using gitolite on a CentOS 6.2, and I created a new repository,I can successfully clone, pull, commit and push files to this new project, but when I logged in this server, trying to find my project files on it, I could not find them. the repository is in /home/mygituser/repositories/myproject.git/ , but none of my pushed files can be found any in there.
Is gitolite keeping the actual project contents somewhere else or is there a way to config and seperate project contents and its repository?
This is driving me crazy, any help will be highly appreciated.

Gitolite operates with bare repositories.
A bare repo has no working tree, meaning no files.
That is why, by the way, your repo root directory ends with .git: it is a naming convention to reference bare repos.
See "Git push only for bare repositories?" for more.
Your repos are managed by default on:
~git/repositories/myrepo1.git
~git/repositories/myrepo2.git
Generally, you don't need to look to the content of a repo while being on the server: you simply clone it on a client and look it there. (the clone won't be a bare repo by default)
You could clone it on the server, if you have a proper ~git/.ssh/id_rsa(.pub) key declared as a user in the gitolite.conf file.
It is what I do, as a test, after installing/updating gitolite on my server.
That works because of my local ssh config file:
Host gitolitesrv
Hostname localhost
User #USERNAME#
Port #PORT_SSHD#
IdentityFile #H#/.ssh/gitoliteadm
So I have a ~git/.ssh/gitolite(.pub) private and public key dedicated to gitolite admin, which I can use locally on the server to clone gitolite repo if I want.
That is because I use that same key to setup gitolite:
GITOLITE_HTTP_HOME= gitolite setup -pk "${H}/.ssh/gitoliteadm.pub"
If you have a similar setup, you can then clone any repo on the server:
git clone gitolitesrv:gitolite-admin "${gtl}/ga"

Related

How do i add and sync my local git on server? What is bare repo?

I am using git from a long time but never set it up on server. Refereeing to this Git: move existing repository from PC to server, clone from server
I have initiate a bare repo on server but while adding origin in local
"git remote add origin server:path/to/repo" i have no idea what to add here. My site is getwalkwel.com and user is getwamld
Thanks
Origin is the name of a remote which is typically created automatically when you clone a repo from another repo. The origin reference in the cloned repo will be created to point back to the repo that was cloned from.
In your case, where the bare repo was actually created later from your working repo, you will create origin in your working repo to point back to your new bare repo.
This is done with:
git remote add origin /barerepo/fullname
If your bare repo is going to line on a different machine, then you need the URL to reach the repo instead of just a file path.
For instance, you might have myuser#myserver:path/to/repo
Bare repository in Git is a repository which only contains version control information only in fact this will not have .git sub-directory or any working files.
This kind of repository is helpful when you need to share or divide your work between few people for example in work environment you and your team mates are working on same project and you all need to see changes and all needs to do push to repository in this case this repository is more useful.
You can add the remote repository to local git repo
$ git remote add origin ssh://myserver.com/var/git/myapp.git
pushing to remote repository:
to push our local master branch to the origin's master branch. You can do that using the git push <target> <local> command.
$ git push origin master
click here for more information on how this works

How to clone git repo from Windows to Linux?

I previously kept a bare git repository on a Linux server and a working copy in my local Windows laptop for development (syncing to the server using TortoiseGit over ssh). The server version was deleted/lost so I want to recreate the repo on the server using the latest commit from the local working copy on the Windows machine.
What is the best way to create this new remote bare repo copy on the remote Linux server from the Windows working copy?
You can re-create the linux server repo using
mkdir -p myrepo.git
cd myrepo.git
git init --bare
On the local copy, assuming the remote URL is the same, do
git push origin <branch refspec>
for example
git push origin master
Note: If the remote URL has changed you can use
git remote set-url origin <new-url>
Just create the repo on the server, then add the repo to your local one as remote if it is not the same location as before and push to it.
Follow these steps:
Create a bare repository on remote.
I guess the answer provided by ad22 is good enough for you:
mkdir -p myrepo.git
cd myrepo.git
git init --bare
Otherwise, you need to find out how to create a bare repository on server.
Copy or Memo the URL of that just created bare repository.
(Of cause, you need to have the right for accessing the URL.)
Add a new remote for your local repository.
Since you already have a local repository,
Right click in that repository, Click TortoiseGit -> Settings,
Give the remote a shortname and URL you copied
Add it and apply the setting.
See:
Push to remote by right clicking in local repository and click Push item.
In Push dialog,
Select the remote you just added.
Check the Push all branches checkbox if all branches can be public, otherwise you need push each branch one by one.
Check the Include Tags checkbox if you want to push all tags.
Suppose that's all. ^__^
On your Windows machine:
git clone --bare /path/to/local-working-copy-of-the-repo
The above command will create local-working-copy-of-the-repo.git folder.
Now copy the folder(bare repository) on to the Linux server.
Hope this helps.

Git push to cPanel account - Push did not update modified file

SOLUTION BELOW - How to use git to push to cpanel server
I finally got somewhere with setting up Git between my localhost (WAMP setup on Windows 8.1) and my Linux server (CentOS 6.6 x64 with cPanel 11.46.2).
Locally I created a bare clone: git clone --bare my_project my_project.git
NOTE: my_project is an example name, not the real name, and from this doc here: http://git-scm.com/book/en/v2/Git-on-the-Server-Getting-Git-on-a-Server
I copied the my_project.git folder to my server's root directory /home/myuser/public_html/
so now in the root directory I have:
cgi-bin
my_project.git
This is one area I am unsure of. Do I have to do an init (using putty) on my server in the public_html directory? I read something about a bare init? I just want to push (from my PC) the website I already have under Git control, to the server. When I make a change to 1 file, push that change to the server so it's updated live with a push. The website is DONE and ready to be live. I have already manually moved back and forth for live testing on the server. My last step is to get the Git setup correctly, so any further changes I can just push them to the server without the need of FTP.
I added a remote origin: git remote add origin ssh://myuser#thedomain.com/home/myuser/public_html/my_project.git
I tried to push to it, and got "Permission denied (publickey)". I already had an id_rsa and id_rsa.pub key locally on my PC, so I copied them and renamed them to id_rsa.myname id_rsa.myname.pub (where myname is my first name). I then copied them to the .ssh folder through FTP (FTP as cpanel user, and it's the directory your dumped into, above public_html), same as /home/myuser/.ssh/ directory.
Once they where there, I added them to 'authorized_keys' using Putty logged in as the cpanel user (my private ppk) by doing:
cd .ssh
cat id_rsa.myname >> ~/.ssh/authorized_keys
cat id_rsa.myname.pub >> ~/.ssh/authorized_keys
After doing that, a push appeared to work. Because I was having a key/auth issue, I used Git Gui version, which was setup and worked fine locally. I added the origins through Git Bash though. When I did "Remote > Push" in the Gui version, I got:
Pushing to ssh://theregistrybank#theregistrybank.com/home/theregistrybank/public_html/yiire gistrybank.git
stdin: is not a tty
To ssh://myuser#thedomain.com/home/myuser/public_html/my_project.git
44ae034..0388a05 master -> master
updating local tracking ref 'refs/remotes/origin/master'
Before doing the push, the only file modified (diff from the bare clone I transferred to the server) was my .gitignore file. I added 2 more exclusions to it, and committed it locally. So I was trying to push the change in that file. After I did the push, it said "success" in green and appeared to work. However, when I check the file in FileZilla, the .gitignore file is not the updated one that I just committed locally.
I think I am close, but missed a step somewhere. I tried to be as descriptive as possible.
And putting the source on GitHub is not an option as the client does not want the source public, and does not want to pay for the private repos. I should be able to push from my local setup to the cPanel server so I don't have to transfer thousands of files every time. I actually transfer a zip file, and unzip on the server lol.
Server Info
cPanel 11.46.2 build 0
CentOS 6.6 x86_64 kvm build01
Yes, Git is setup on the server, and working, and git --version reports:git version 1.7.1
Git on my PC: git version 1.9.4.msysgit.2
Thank you in advance.
SOLUTION
Thanks to #VonC I was able to get this to work :)
You need somewhere for your git repo to sit. I created a 'git-repos' folder in '/home/cpaneluser/git-repos' to house my repos for this cpanel user.
First step is to create a bare repo: http://git-scm.com/book/en/v2/Git-on-the-Server-Getting-Git-on-a-Server - I only followed the first step, basically created the bare repo 'my-project.git'
Before putting it on your server, rename 'my-project.git/hooks/post-receive.sample' to just 'post-receive' so it will be ran. Edit it with your editor, and add the line that #VonC gave us in his chosen answer:
#!/bin/sh
umask 0022
GIT_WORK_TREE=/home/cpaneluser/public_html GIT_DIR=/home/cpaneluser/git-repos/my-project.git git checkout -f
Note: I am using cpanel, so your path's may be different, and your umask could be different. 0022 is for 0644 file permissions. Without the umask, I was getting 500 Internal Server Errors, because the files were created with 0664 permissions instead.
Using FTP or whatever you like, copy the 'my-project.git' bare repo to your server to '/home/cpaneluser/git-repos'. Then go into 'my-project.git/hooks' and change the permissions of post-receive to have execute permissions. For me, 0744 worked fine. This was the magic sauce :)
Locally, add your remote (must be in your git project): git remote set-url origin ssh://cpaneluser#yourdomain.com/home/cpaneluser/git-repos/my-project.git
Now if you try to push now, it won't put the files in 'public_html' because the git tree (terminology?) matches and is up to date. If they are up to date, it seems to skip over executing your 'post-receive' hook. That means your bash script never ran, and it never checked out the files to your working tree.
We need to manually run the 'post-receive' bash script to create all the files of our project in the 'public_html' directory.
cd to '/home/cpaneluser/git-repos/my-project.git/hooks'
Run: ./post-receive
Boom, all your files are in 'public_html'. Now you can work locally, then push to your cpanel server as expected :)
I had a similar problem with my cPanel account, git was set up but for some reason I couldn't push to it. After a lot of head-banging I realized that the root of the problem is like you pointed out that although git is set up, the repo is empty so there's nothing for it to track.
This happens when you set up an empty repo in cPanel and then try pushing a local repo that you've already created, as opposed to cloning it first from github or your local repo (which is what happened to me because for some reason I couldn't access my github from the cPanel git interface even though I had set up a SSH key)
The simple solution that I found is to manually clone the repo using the terminal in your cPanel account
On your cPanel dashboard, under the "advanced" section, you'll find the terminal. You'll get a warning saying that you could mess up your server if you don't know what you're doing, click ok and you're in.
Now you just have to clone your repo the same way you would if you're cloning onto a local machine.
Navigate to where git was set up in your cPanel
cd repositories/<nameOfYourRepo>
And run the clone command
git clone <URLofYourGithubReop>
You'll be asked for your github username and password if it's a private repository
And that's it, you're good to go
What you have copied (my_project.git) is a bare repo, meaning one without a working tree (the actual checked out files).
Read for instance "Git workflow - Setting up a build process".
That means pushing to if won't change anything in /home/myuser/public_html/
The missing piece is a post-receive hook (in /home/myuser/public_html/my_project.git/hooks/post-receive, make sure it is executable: chmod +x), in order to checkout the repo in /home/myuser/public_html/.
#!/bin/sh
GIT_WORK_TREE=/home/myuser/public_html GIT_DIR=/home/myuser/public_html/my_project.git git checkout -f

How to connect local and remote Mercurial repos?

Typically, in Mercurial, I create a new project by:
Create a new remote repo
Clone the repo locally
Make changes to the local repo
Push those changes to the remote repo
The "remote repo" here is actually our "central/originating" DVCS server (http://ourhg.ourorg.example.com, etc.).
I am now in a situation where I had to use a code generation tool to produce the source code for a simple web app. So the source code exists before the remote repo exists on our hg server. I'm looking for the exact shell commands I need to execute to get this properly pushed to the remote repo.
I believe it should be something like this:
Use the code generator to generate the code, say, at /home/myuser/myapp.
Initialize an hg repo for myapp locally on my machine (hg init)
Add the generated source code for myapp to this local repo (hg add, then hg commit)
On ourhg.ourorg.example.com, create the new remote repo (manual steps)
???
Push the changes sitting in my local repo to the remote repo (hg push)
I know there is something missing in between Step #4 (creation of the remote repo) and Step #6 (pushing to the remote repo). There surely needs to be some "connection" step where my local repo and the remote repo realize they represent the same project/source code/etc. This is my hangup here, so I ask: what is Step #5?
what is Step #5?
Discover URL of this repo. Because it's empty repo, you can don't worry about "related|unrelated"
There's nothing you need to do to associate them. You can do hg push URL_OF_REMOTE on your local and it will work. If you don't want to have to provide the URL each time you can edit (creating if necessary) .hg/hgrc in the repo and set the default= value in the [paths] section. Something like this
[paths]
default=URL_OF_REMOTE
That's optional though.
Just use your origial steps, with caveat:
Create a new remote repo
Clone the repo locally (this will set default path of local to remote).
Make changes to the local repo (Use the code generator app to generate the code in the local repo).
Push those changes to the remote repo.
With this flow, you don't have to manually update the path to the remote repo.

Deploying git repo to "production" server

I have a git repo where a group of developers and I are collaborating on project code. occasionally, we'd like to copy the git repo to a VPS (setup as Linux server) that has an external IP address (w.x.y.z).
I can go into an SFTP client and navigate up the folder hierarchy to the server root and then navigate down to /var/www/ (server web root) to drop my files in but I'd like to deploy to the server through the command line instead.
My goal is to configure the Linux server as a remote git directory but don't know how to go about navigating up the file hierarchy to have git recognize that the remote branch repo needs to go into /var/www/.
Brief search has uncovered git remote add origin username#w.x.y.z then use git push origin.
It seems that connecting this way to w.x.y.z will land me at the home folder of 'username', not the root web directory (/var/www/) when accessed via the browser.
Does anyone have insight into how I should go about setting up a remote directory for deploying a git repo to a "production" server?
You appear to be doing this a rather non-obvious way. I think what you want to do is copy the git repo to somewhere else (the vps server). The standard way to achieve this is git clone.
In your /var/www/ directory or an appropriate subdirectory thereof, do:
git clone [URL-FROM-GITHUB]
That will clone the git repository to your VPS. You can then update it with
git pull
could script this with
ssh my.vps.server 'cd /var/www/whatever && git pull'
However, normally you don't want the entire project in '/var/www/...' because that would also put stuff you did not mean to deploy there, e.g. the .git directory. Hence perhaps better to clone the repo within your home directory, and make a small script to rsync the appropriate /var/www/ directory against your repo, using --exclude to remove files you don't want, or just rsync-ing a subdirectory of the repo.

Resources