I have various Git projects that are on my local machine. I have a server that I would like to use as my remote Git Repository. How do I move my local Git Repositories (Pro
Perhaps this is "backwards", but I've always done
git clone --bare localrepo localrepo.git
scp -r localrepo.git remoteserver:/pathTo
mv localrepo localrepo-prev
git clone remoteserver:/pathTo/localrepo
prove out the new repo is fine, with git status/log etc to make me feel better
move any files not under version control from -prev to the new localrepo
rm -rf localrepo.git localrepo-prev
Create a git repository on the server (you can use gitolite/gitosis or just a normal user account + pubkey ssh auth), add the server to your local git repository using
git remote add name url
and use git push -u name master
(-u
marks the current branch as tracking so you can just git pull
instead git pull name master
).
On the server side (debian based system):
adduser --system --home /home/git --bash /bin/bash git
su - git
mkdir .ssh
cat yourkey.pub > .ssh/authorized_keys
Now, create a new bare repository for each local repository using
mkdir projectName
cd projectName
git init --bare
After that, the url would be git@yourserver:projectName
.
I have a local repo with commit logs. I wanted to add it a a new github remote repository with all the commit logs preserved. Here is how:
create the remote repo on the github. And get the the repo URL from the "Clone or Download" green button, such as https://github.com/mhisoft/eVault.git
If the local repo was attached to an old orgin. remove it first
git remote remove origin
Add the existing repository from the command line
git remote add origin https://github.com/mhisoft/eVault.git
git push -u origin master
There is a good tutorial on Ralf Wernders blog. Assuming you know how to create a repository on the server, or that has already been done:
git remote add <remote> <url>
To add a remote to your local repository. <remote>
is the name of the remote (often "origin"). <url>
is the url to your repository with write access (like git@...)
git push <remote> <branch>
To move the commits over to the origin. <branch>
is the branch you're pushing (often "master").
First, create a git repo on your server
git init --bare /path/to/repo
Then add the remote repo to your local one (ssh:// or https://)
git remote add origin ssh://server/path/to/repo
And, push files/commits
git push origin master
And finally, push tags
git push origin --tags
If you want a normal (eg: not bare) repository, just copy it. There is nothing special that needs to be done.
If you want to use a bare repository on the server, just initialize it on the server, add it as a remote on the "local" copy, then push to it. (git push --mirror
will get everything through.)