2

I'm trying GIT and i ran into an issue.

I have my local machine (let's call it MAC) and a server (let's call it SERVER). It's a local server, I access it through an alias in my desktop.

I want to create a GIT repository in this SERVER, in which I'll keep my files and pull these files into my MAC. Then, after editing, I want to commit these changes to SERVER.

SERVER        MAC         SERVER
source  -->>  copy  -->>  commit

It sounds very GIT-like, but I can only find these tutorials for remote servers, with logins and passwords and such. How to do that with a local server?

Other people use this local server and it would be nice if they could pull and commit this same SERVER repository.

Thanks a lot.

ps: I'm using SourceTree GUI but I'm no stranger to terminal.

angelod1as
  • 95
  • 1
  • 11
  • What's the difference between a local and remote server? Also, see this: http://stackoverflow.com/questions/315911/git-for-beginners-the-definitive-practical-guide – Greg Apr 27 '16 at 17:38
  • That is a good question. What is the difference? When I say Local Sever, I mean I can access it via my computer, no a website like github or a server located somewhere else (I don't know if I'm being clear) – angelod1as Apr 27 '16 at 17:53
  • If you have git installed on the server, and have SSH access to it, that's all you need. If you want more than a very basic setup, you can use something like [Gitolite](http://gitolite.com/) on top of that. If you want a full-blown self-hosted GitHub clone, you can use something like [Gitlab](https://about.gitlab.com/) or [Gogs](https://gogs.io/). See http://stackoverflow.com/questions/10888300/gitosis-vs-gitolite – Alex Howansky Apr 27 '16 at 18:01

1 Answers1

2

There is no difference in accessing a central Git repository on local and remote servers. All tutorials are valid in either case. For the basic access you simply need:

  1. Create a normal user account on the server (e.g. git or george).
  2. Set up a SSH key access to that account. There are many tutorials online, just pick one. For example Github tutorial. The objective is that when you are on your Mac you can SSH to the user account on the server without a username/password, just with the key.
  3. Login to the user account on the server create a bare Git repository.

That's it, then you can access that repository from your Mac.

For example, assume that the server name is myserver.com and it's IP is 192.168.1.50. You login to that server over SSH:

ssh george@192.168.1.50

If the key is set up correctly, you are now logged in (without providing username/password). Now create the bare repository:

mkdir mygit
cd mygit
mkdir myrepository.git
cd myrepository.git/
git --bare init

Then on the Mac create a new repository:

mkdir mylocalrepo
cd mylocalrepo
git init
echo "sometext" > firstfile.txt
git add firstfile.txt
git commit -m "First commit"

Now you can specify the repository created on the server as the remote repository for your local repository. On your Mac (or any other machine on which you want to access that repository):

git remote add origin george@192.168.1.50:mygit/myrepository.git
git push origin master

Alternatively, use the server name rather than IP, and a different remote name:

git remote add origin2 george@myserver.com:mygit/myrepository.git
git push origin2 master

Once you have those basics working you can then start thinking about adding a WWW interface.

Greg
  • 8,230
  • 5
  • 38
  • 53
  • 1
    more info on server setup from the git-scm book: https://git-scm.com/book/en/v1/Git-on-the-Server-Setting-Up-the-Server – xero Apr 27 '16 at 19:46