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:
And:
Relevant info:
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:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With