Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

basic git understanding problems

Tags:

git

Situation

I've never before used git or any other version control. Now I've got a web-project that needs to have a stable and a developement version, with both running on the same server in different directories.

  • Stable: /var/www/afod/afod
  • Development: /var/www/afod_dev/afod

Now I want to use git to sync changes from the dev-version into the stable-version and as I've never before used VC-systems I don't seem to get how to do this.

What I have done until now

I created a git repository in /var/www/afod/afod and cloned it into the dev directory via:

cd /var/www/afod_dev/afod
git clone /var/www/afod/afod

Now I've got 2 repositories which I want to keep synchronised using git pull on the stable-version side.

The problem(s)

I've already got 2 branches, web and dev. But as it seems git pull in the stable-version syncs from both branches. But I only want to sync the changes to the stable version, that I have already merged to the web-branch in the dev-version.

total confusion

I hope I could somehow point out my problem. I seem to have a basic understanding problem of how git works, but it seems to be the right software to do what I want to do. I basically want to have a branch that is automatically synced into the stable version and other branches I merge into it. But the developement must be in a different directory than the stable version is.

Concerning the first answer from Billy Moon

Well, stable and dev are hosted under a different domain in a different apache vserver. It wouldn't make any sense to work on a dev-branch that is in the directory people see when they browse the site.

So my idea was to clone the repository and then sync these.

Do I get something wrong here? How do you deal with such configurations?

like image 600
SirSiggi Avatar asked Oct 10 '22 21:10

SirSiggi


1 Answers

Branches

I think you are on the right track, but a llittle confused with the idea of a branch. You can visualize a branch as two branches on a tree. Both have the same trunk, source, but the tips are different. The differences are between the same code base and can be minor or major. When you run the command git checkout <branch_name> you are telling git you want different tips of the tree to be active, copied into the working directory.

In your case, one branch has the development code, and the other has your stable code. To get the code from the dev branch into the web branch, you use git merge <branch_to_pull_in> This combines the tips of those two branches so their content is the same. For more information on branches in general, Here is a generic non git page.

Possible Solution

Below is a solution that could work for you. There are other possible work flows, but this is one of the simplest ones.

Clone your development repository into /var/www/afod/afod. Than from within /var/www/afod/afod run git checkout web and from your devfolder, ensure that you are on the dev branch. git branch should have a line like this * dev.

You now have two different branches of the same repository checked out into different subfolders. Do your work in dev as you have. Once you feel it is stable, from within your dev folder run git checkout web. Than, git merge dev. This will merge those changes into your web branch. Now from within /var/www/afod/afod run git pull. This will pull your chnages into the production server. Both dev and web will be pulled over, but only the one that is checked out will be in your working directory.

When you want to work in the dev branch again, run git checkout dev from within the dev folder.

like image 198
Andy Avatar answered Oct 13 '22 10:10

Andy