0

Up until now I worked on my websites alone and without any kind of version control right on my server (basically opened and modified files stored in each /var/www/vhosts/domain.tld/httpdocs-Folder directly over sftp with an IDE/over ssh) since it was sufficient for my needs.

Now I'm searching for the best way to collaborate with other developers and use git for all of these already existing websites.

Is it recommendable to create multiple bare repositories like

/home/git/domain_1.git, /home/git/domain_2.git, ...

with e.g. git init --bare domain_1.git in some folder like /home/git/ with my root-Account and then somehow** add each already existing /var/www/vhosts/domain/httpdocs-Folder to each of these bare git repos and then add an hook (post-receive?) to each repo to overwrite it's specific /var/www/vhosts/domain.tld/httpdocs-Folder at every push. And then give every developer access via the git-User with URL like ssh://git@1.2.3.4:/home/git/domain_1.git for each single repo.

If that way should be fine: Is there any kind of walkthrough out there? I couldn't find anything and I'm searching for a proper solution since days, no kidding...

Or is there any better/best practice to solve this kind of issue?

** = (how?! since no git command like git add works on these bare repos...)

Dez
  • 5,702
  • 8
  • 42
  • 51
SEA2605
  • 21
  • 4
  • 1
    it's opinionated what is "best" way to setup source control... just use bitbucket free plan for under 5 users https://confluence.atlassian.com/bitbucket/bitbucket-cloud-plan-details-224395568.html and then read get started https://confluence.atlassian.com/get-started-with-bitbucket/set-up-a-team-861176358.html easy peeeezy – Luke Hutton Nov 14 '17 at 23:07

2 Answers2

1

First thing congratulations on deciding on to use a version control system to manage your codebase. Second thing you don't need multiple bare repositories to maintain multiple folders in your source control. Since you have asked for the best practices I will directly get into what you need to do to set yourself up with a source control.

You need a DVCS tool ---> GIT One repository to host your source code---->Github/Bitbucket Cloud Once you have the repository created in the above Source Control Management Tool create and empty repo and pull all your code inside that repo. Follow this for how to?

Next you need to design a branching strategy so that other developers can keep developing on the same codebase. I would start with something simple like one master branch(to maintain different release versions) and one integration branch named develop. Your developers need to create feature branches to implement new features. You can review them and merge them on to integration and then on to master. To learn more you can follow https://git-scm.com/book/en/v2/Git-Branching-Branching-Workflows

user_dev
  • 1,357
  • 3
  • 20
  • 46
1

You don't want to use a bare repo (since it won't have a working directory).

To create your repos, you can use git init in the root of whatever directory has your files. Even better, use github/bitbucket and it will create the repo for you. Then you can clone it, do your initial commit, and push.

The key point here is that the "main" place you are storing your code is not on the live server and not on your development machine. This also makes it so everyone doesn't have to ssh to your live server to do a push.

You then clone your repos wherever you need them, probably on your development machine to make changes. commit and push back to bitbucket. Then you'd have another clone on your live server (for you at /var/www/vhosts/domain.tld/httpdocs-Folder) where your "deploy" process is to git pull to get the latest changes that have been pushed to bitbucket.

Other options include having a process watch your bitbucket repo for any commit to your master branch and automatically pulling.

For this to be safe, you'll need to research branching strategies. Pick one and make sure all committers know how to follow it.

A simple one is to have the master branch be "what is live in prod" and develop be where you make change. So changes flow from developer machine develop branch to master branch to bitbucket to live server. Using pull requests (with code reviews) for merging code to master will help keep master stable.

Jeff
  • 43
  • 5