Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git workflow (Dev>Staging>Live) basic technical questions

I'm quite new to Git (and VC for that matter) and I'm struggling a bit to understand the concept behind the Dev>Staging>Live workflow using branches.

I'm trying to apply part of this workflow, that uses dev branches and release branches instead of a fixed staging.

Before trying to use Git, I had the "same" workflow using SVN. But instead of creating branches for each stage, we used separated repositories for it. Now that I'm trying to apply branches, things are getting a bit blurry.

I can understand the idea behind the workflow, but can't get it from a technical point of view.

The steps that I'm following to create it:

Create folders

user:/var/www/$ mkdir dev.example.local
user:/var/www/$ mkdir staging.example.local
user:/var/www/$ mkdir example.local

Init repositories

user:/var/www/example.local$ git init
user:/var/www/example.local$ git remote add origin [email protected]:user/example.com.git
user:/var/www/example.local$ echo "README" > README
user:/var/www/example.local$ git commit -am "First"
user:/var/www/example.local$ git push origin master

user:/var/www/example.local$ cd ../dev.example.com
user:/var/www/dev.example.local$ git clone [email protected]:user/example.com.git .
user:/var/www/dev.example.local$ git checkout -b dev
user:/var/www/dev.example.local$ git push origin dev

user:/var/www/dev.example.local$ cd staging.example.com
user:/var/www/staging.example.local$ git clone [email protected]:user/example.com.git .

Some work on dev branch

user:/var/www/dev.example.local$ echo "New" > newfile
user:/var/www/dev.example.local$ git add .
user:/var/www/dev.example.local$ git commit -am "Some new file"
user:/var/www/dev.example.local$ git push origin dev

When things are ready for a new release

user:/var/www/staging.example.local$ git fetch
user:/var/www/staging.example.local$ git checkout -b release-0.1 dev
user:/var/www/staging.example.local$ git push origin release-0.1

user:/var/www/staging.example.local$ cd ../example.com
user:/var/www/example.local$ git fetch
user:/var/www/example.local$ git merge --no-ff origin/release-0.1
user:/var/www/example.local$ git tag -a "0.1"
user:/var/www/example.local$ git push origin master

user:/var/www/example.local$ cd ../dev.example.com
user:/var/www/example.local$ git merge --no-ff master
user:/var/www/example.local$ git push origin dev

I'm pretty sure I'm not following the correct steps. So, what's the "right way" to:

  • create the dev, staging, live folders and init the git repo in each one of them?
  • checkout/merge new releases?
  • merge from the release to live?
  • create the whole environment?

And:

  • where should I run those git commands? on my local repo? for each one of the stages?

Relevant info:

  • I'm using BitBucket
  • This is for website (Drupal) development
  • My master branch is the live stage
  • There are about 3 developers working at the same time, and each one in a different country
like image 552
dmmd Avatar asked Jul 12 '12 22:07

dmmd


1 Answers

You don't need to create different repositories. What you should learn and you'll probably love about git is how easy it is to work with branches. So step 1:

  • Forget about anything you know from your SVN background

Now that we are all set, here is the idea. Let's say you have currently only master on your bitbucket:

  • Clone the repository:

    $ git clone [email protected]:user/example.com.git
    $ cd example.com
    
  • Create your branches:

    $ git branch dev
    $ git branch staging
    
  • Let others know about these branches:

    $ git push origin dev
    $ git push origin staging
    
  • Start working!

    $ git checkout dev
    $ touch new_file
    $ git add new_file
    $ git commit
    $ git merge master         # and resolve conflicts
    $ git checkout master
    $ git merge dev
    $ git push origin
    

Note: The example above is a simple branch-experiment-merge, and would probably not reflect the exact workflow as your tutorial.

So in short, you don't have different repositories, but branches in a single repository. Between these branches, you can merge as much as you want with whatever workflow you like. You can have additional branches that are not pushed to origin, so they are hidden from others. You should also of course git fetch/git merge the branches you want to work on every often to make sure you get the latest changes from other collaborators.

like image 71
Shahbaz Avatar answered Nov 09 '22 23:11

Shahbaz