Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git workflow without a server

Git is supposed to be a decentralized system, but all the tutorials and best practice workflows I have found on Google suggest using a server (usually GitHub, or else set up your own)

I am using git for small personal projects (2-3 people), where can I find a best practice workflow for syncing changes directly between the team members machines.

Alternatively, what are some compelling arguments for why I should avoid this and instead set up a 'central' server?

like image 930
Ben Page Avatar asked May 10 '11 08:05

Ben Page


People also ask

Is it possible to use Git locally?

Git allows you to create a local repository on your machine. Only when you're actually ready to publish it to a remote is when it becomes available to the public.

How do I use Git standalone?

If you want to use git offline just install git, go to the root directory for your files and run git init to initialize the repository. You can then run git add file_path , git commit -m "First commit" etc. The repository is stored under the .

Can you use git offline?

By design Git works quite happily with no remote repository. You can branch, stage, and commit files just like normal. This works great if just a single machine is used for development, but this is often not the case.

Can I use Git without using GitHub?

You can use Git without ever using an online host like Github; you would still get the benefits of saved backups and a log of your changes. However, using Github (or the others) allows you store this on a server so that you can access anywhere or share.


2 Answers

Depends on what you mean by "server". Git will work happily without a central server, although many teams find it convenient to have a central repository.

If by "server", you mean "install server software", git will also work (central repository or not) without any special software, through ssh or on the file system.

See this document for possible workflows

Workflow with common repository

The workflow that many use is that all developers "push" (send) their changes to a common repository, and get all the changes from that repository. Something like this:

  • Developer A pushes to central
  • Developer B pushes to central
  • Developer C pulls (getting changes from A and B)
  • Developer A pulls (getting changes from B)
  • ...

In this case the central repository can be on one of the Developers computers, on github, or any other place

Workflow with Email

You can also use git without any server, just using email. In this case the flow would be like this:

  • Developer A sends changes as an email to the team
  • Other developers apply the changes from the emails

This can even be done in a semi-automated way

Workflow without a central server

You can setup git to use more than one "remote" repository. The caveat is that you should never push to a repository that is checked out (that is, a Developer copy on which someone is working). So in this case the flow would be like this:

  • Developer A makes changes
  • Developer B makes changes
  • Developer C pulls changes from A
  • Developer C pulls changes from B
  • Developer B pulls changes from A
  • ...
  • No one must ever push

IMHO this type of workflow will quickly lead to confusion and breakdown.

like image 84
averell Avatar answered Sep 20 '22 00:09

averell


What you need to do first, is to think through what kind of workflow you have already and configure git to work with that. Once you have something up and running, you can fine tune it. There is no need to setup a separate computer as a server. If you are accustomed to have a central repository all you need to do is to create a bare repository that everyone pushes to. Why not on the local network?

Central repo:

mkdir foo.git cd foo.git git init --bare 

Your repo:

mkdir foo cd foo git init // add files git add . git commit -m "Initial commit" git remote add origin //path/to/central/repo/foo.git git push origin master 

Other repos:

git clone //path/to/central/repo/foo.git 

Now anyone can push and pull directly from master branch. This should be enough to get you started.

like image 43
ralphtheninja Avatar answered Sep 18 '22 00:09

ralphtheninja