Skip to content
Permalink
Browse files
finished gitflow section
  • Loading branch information
aa7401 committed Jun 12, 2017
1 parent e16eb14 commit 0c1902d078f83a3c8e1a2c2fb4c632b988e3cb5c
Showing 1 changed file with 254 additions and 4 deletions.
@@ -1,11 +1,11 @@

# Version Control

1. Cloning and ...
1. Git Remotes *
2. Branching
3. GitFlow

## 1 Cloning and XXX
## 1 Git Remotes

```
git clone https://github.coventry.ac.uk/304CEM-1718SEPJAN/currency.git
@@ -39,6 +39,7 @@ Date: Mon Jun 12 07:45:22 2017 +0100
added start of gitflow
```
You navigate using `space` for the next page, `w` for the previous page and `q` to quit.

### 1.2 Remotes

@@ -49,6 +50,7 @@ $ git remote get-url origin
https://github.coventry.ac.uk/304CEM-1718SEPJAN/TEACHING-MATERIALS.git
```


## 2 Branching

List branches.
@@ -57,6 +59,65 @@ $ git branch
* master
```

Display the branch structure in the log output:
```
git log --graph --abbrev-commit --decorate
* commit 37cedee
| Author: Mark Tyers <marktyers@gmail.com>
| Date: Sat May 27 10:45:54 2017 +0100
|
| chapter 1 structure done
|
* commit e90e847
|\ Merge: 7b4e193 5a2aaad
| | Author: Mark Tyers <marktyers@gmail.com>
| | Date: Sat May 27 08:38:00 2017 +0100
| |
| | added more samples
| |
| * commit fa37b77
| | Author: Mark Tyers <marktyers@gmail.com>
| | Date: Mon May 15 13:35:34 2017 +0100
| |
| | completed first example
| |
* | commit 7b4e193
|/ Author: Mark Tyers <marktyers@gmail.com>
| Date: Sat May 27 08:35:07 2017 +0100
|
| minor changes
|
* commit 40f08a9
| Author: Mark Tyers <marktyers@gmail.com>
| Date: Sun May 14 15:50:00 2017 +0100
|
| added content to chapter 1
|
$ git log --graph --abbrev-commit --decorate --pretty=oneline
* 480d68b chapter 2 structure complete
* 37cedee chapter 1 structure done
* e90e847 added more samples
|\
| * 5a2aaad week 2 structure
| * 085df46 finished chapter 1
| * fa37b77 completed first example
* | 7b4e193 minor changes
|/
* 40f08a9 added content to chapter 1
$ git log --all --decorate --oneline --graph
* 37cedee chapter 1 structure done
* e90e847 added more samples
|\
| * 5a2aaad week 2 structure
| * 085df46 finished chapter 1
| * fa37b77 completed first example
* | 7b4e193 minor changes
|/
* 40f08a9 added content to chapter 1
```

Remote Tracking Branches

If you check out a local branch Git automaticall creates a _tracking branch_ which is a local branch that has a direct relationship with a remote branch. This is why Git knows which branch to use when you run `git pull`. These branches are read-only and act as bookmarks to where your remote branches were last time you connected to them.
@@ -67,6 +128,8 @@ $ git branch --all
remotes/origin/master
```

You can get a list of the commits on the remote branch `git log origin/master`

TODO

## 3 Git Flow
@@ -106,7 +169,7 @@ git clone https://github.coventry.ac.uk/304CEM-1718SEPJAN/currency.git gitflow

1. Performing Git setup (name, email, editor, cache)
2. Install GitFlow `sudo apt-get install git-flow`
3. Initialise GitFlow `git flow init`
3. Initialise GitFlow `git flow init`, accepting the defaults for all the options.
```
$ git flow init
Which branch should be used for bringing forth production releases?
@@ -130,5 +193,192 @@ $ git branch -a
master
remotes/origin/master
```
The next step is to implement the three features, each will be in its own feature branch, the suggested branch names are shown:

TODO
1. modify the script to ask for the currency to convert to and display only the one conversion rate (`display-single-currency`).
2. instead of printing the exchange rate, ask for the amount to be converted and them return the equivalent in the chosen currency (`ask-for-amount`)
3. use the [OpenExchangeRates](https://openexchangerates.org/api/currencies.json) API to display the full name of the chosen currency (`show-full-currency-name`).

```
$ git flow feature start display-single-currency
Switched to a new branch 'feature/display-single-currency'
Summary of actions:
- A new branch 'feature/display-single-currency' was created, based on 'develop'
- You are now on branch 'feature/display-single-currency'
```

If we list our local branches you will see that there is a new branch and that it has been checked out.
```
$ git branch
develop
* feature/display-single-currency
master
```
Your next step is to implement the feature. Remember to commit your code on a regular basis, you should aim to do at least 2 commits.

If you plan on collaborating with other developers on this feature you will need to _publish_ it. This will push the branch to your GitHub remote which means it will be available for the other developers to use. If you don't publish it it won't be visible on your GitHub remote.
```
git flow feature publish display-single-currency
```

Once the feature is completed you can finish the feature. This will open our default code editor (we specified the `nano` editor), accept the default commit message then save and quit the editor using `ctrl+o` and `ctrl+x`.
```
$ git flow feature finish display-single-currency
Switched to branch 'develop'
Merge made by the 'recursive' strategy.
index.js | 27 ++++++++++++++++++++-------
3 files changed, 72 insertions(+), 7 deletions(-)
create mode 100644 .eslintrc
create mode 100644 .gitignore
Deleted branch feature/display-single-currency (was cd5b304).
Summary of actions:
- The feature branch 'feature/display-single-currency' was merged into 'develop'
- Feature branch 'feature/display-single-currency' has been locally deleted
- You are now on branch 'develop'
```
Viewing the commit log you will see something like the following:
```
$ git log --all --decorate --oneline --graph
* 5928d5e (HEAD -> develop) Merge branch 'feature/display-single-currency' into develop
|\
| * cd5b304 prints single conversion rate
| * 4b6d5f0 isolates single currency
|/
* a443a19 (origin/master, master) Added main script file
```
As you can see, the new branch comes off the develop branch and then merged back into `develop` and the feature branch deleted.

Repeat this for the other two features ensuring you create a new branch for each of them.

Release

Once the features are implemented and tested it is time to create a release 1.0.0 using the features of GitFlow.
```
$ git flow release start 1.0.0
Switched to a new branch 'release/1.0.0'
Summary of actions:
- A new branch 'release/1.0.0' was created, based on 'develop'
- You are now on branch 'release/1.0.0'
Follow-up actions:
- Bump the version number now!
- Start committing last-minute fixes in preparing your release
- When done, run:
git flow release finish '1.0.0'
```
If we list the local branches we will see that the feature branch is no longer available and that there is a new branch we will be using to finalise the release.
```
$ git branch
develop
master
* release/1.0.0
```
If you want other developers to work on the release you will need to _publish_ it. This will push the branch to your GitHub remote which means it will be available for the other developers to use. If you don't publish it it won't be visible on your GitHub remote.
```
git flow release publish '1.0.0'
```

When we carry out the final tests on our code we notice that it fails to exit cleanly when the script finishes. This is an issue that needs to be fixed before we can release the product to our end users! The solution is to include the following command immediately after the script displays the results to the user.
```
process.exit()
```
Add this line, test and then make a commit.

Now we can finish the release.

You will be prompted for the commit message (use the default) and will also be asked to provide a tag name, use `v1.0.0`.
```
$ git flow release finish '1.0.0'
Switched to branch 'master'
Your branch is up-to-date with 'origin/master'.
Merge made by the 'recursive' strategy.
index.js | 28 +++++++++++++++++++++-------
1 file changed, 28 insertions(+), 7 deletions(-)
create mode 100644 .eslintrc
create mode 100644 .gitignore
Already on 'master'
Your branch is ahead of 'origin/master' by 7 commits.
(use "git push" to publish your local commits)
Switched to branch 'develop'
Merge made by the 'recursive' strategy.
index.js | 1 +
1 file changed, 1 insertion(+)
Deleted branch release/1.0.0 (was 1677906).
Summary of actions:
- Release branch 'release/1.0.0' has been merged into 'master'
- The release was tagged '1.0.0'
- Release tag '1.0.0' has been back-merged into 'develop'
- Release branch 'release/1.0.0' has been locally deleted
- You are now on branch 'develop'
```
If we look at the commit graph we will see the entire commit history (yours will be longer than this:
```
$ git log --all --decorate --oneline --graph
* df496c8 (develop) Merge tag '1.0.0' into develop
|\
| * 12fe99c (HEAD -> master, tag: 1.0.0) Merge branch 'release/1.0.0'
| |\
| | * 1677906 fixed issue of script not exiting cleanly
| |/
|/|
* | 5928d5e Merge branch 'feature/display-single-currency' into develop
|\ \
| |/
|/|
| * cd5b304 prints single conversion rate
| * 4b6d5f0 isolates single currency
|/
* a443a19 (origin/master) Added main script file
```
And if we checkout the master branch we will see that it contains our working code including the release code.

### Hotfixes

Try running the script and input an invalid code, what happens. The chances are that the error message is printed but then the script continues to execute! This is a serious but in our release code and we will need to implement a _hotfix_.
```
$ git flow hotfix start 'v1.0.1'
Switched to a new branch 'hotfix/v1.0.1'
Summary of actions:
- A new branch 'hotfix/v1.0.1' was created, based on 'master'
- You are now on branch 'hotfix/v1.0.1'
Follow-up actions:
- Start committing your hot fixes
- Bump the version number now!
- When done, run:
git flow hotfix finish 'v1.0.1'
```
Now you need to fix the issue by adding the line `process.exit()` to each error handling block. Once you have finished, you need to commit the changes and then _finish_ the hotfix. Use the tag `v1.0.1`.
```
$ git flow hotfix finish 'v1.0.1'
Branches 'master' and 'origin/master' have diverged.
And local branch 'master' is ahead of 'origin/master'.
Switched to branch 'master'
Your branch is ahead of 'origin/master' by 7 commits.
(use "git push" to publish your local commits)
Merge made by the 'recursive' strategy.
index.js | 57 +++++++++++++++++++++++++++++++--------------------------
1 file changed, 7 insertions(+), 7 deletions(-)
create mode 100644 solution.js
Switched to branch 'develop'
Merge made by the 'recursive' strategy.
index.js | 57 +++++++++++++++++++++++++++++++--------------------------
1 file changed, 7 insertions(+), 7 deletions(-)
create mode 100644 solution.js
Deleted branch hotfix/v1.0.1 (was 725b3ca).
Summary of actions:
- Hotfix branch 'hotfix/v1.0.1' has been merged into 'master'
- The hotfix was tagged 'v1.0.1'
- Hotfix tag 'v1.0.1' has been back-merged into 'develop'
- Hotfix branch 'hotfix/v1.0.1' has been locally deleted
- You are now on branch 'develop'
```
If you switch between the `develop` and `master` branches you will see that your _hotfix_ has been applied to both.

0 comments on commit 0c1902d

Please sign in to comment.