Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions 08_code_management/00_Git_Basics.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# Git Basics

## What is SCM and why Git is different
### Software Configuration Management
- Track changes to code
- Facilitate collaboration working on the same code base
- Identifying causes of defects
- Facilitate build & release process including continuous integration, continuous delivery.

### GIT
- Decentralised
- not locking
- Light weight branching
- No "Trunk"/Special branches - All branches are equal


## Getting Started
### Some terms we will be using
- Working Tree
- Index
- Staging
- Head
### Demonstration 00.1
Taking a directory on the file system initialise as a GIT repo and commit files

- Initialise a repo (run at the root of the project)
> `git init`
- Stage files - Current state of selected files are stage for the next commit
> `git add <files>`
- Commit - Commits changes to the repository
```
git commit
git commit -m "My commit message"
```
- Viewing the status of the working tree
```
git status
```


*Note on staging*: Once a file is stage and further changes made before the commit will not be committed unless those changes are also staged.

### Exercise 00.1
Take your existing code initialise, stage and commit

## Log and Diff
### Demonstration 00.2
Makes changes in the working directory and view differences from HEAD

- View all differences
> `git diff`

- View diffences for specific files
> `git diff <files>`

Commit some more changes a view the log
- View the log
> `git log`

View difference between HEAD and a previous commit
> `git diff <commit> HEAD`

View difference between working directory and a previous commit
> `git diff <commit>`

View difference between two commits
> `git diff <commit> <commit>`

### Exercise 00.2
1. Initialise a new git project to experiment with (we will call this the sandbox project). Try out making changes in working tree and commit changes using the `git diff` command to view the changes.
2. Initialise a new git project for you project code.

### Other index/staging commands
These command update both the Working tree and the index
- Move/rename a files
> `git mv <files>`
- Remove files
> `git rm <files>`

## Demonstration 00.2
Working with GIT in PyCharm/CLion
85 changes: 85 additions & 0 deletions 08_code_management/01_Branching.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# Branching and Merging

## Working with branches in Git
- Git has no special branches. No trunk (though it does have a default branch "master")
- Git branching is lightweight mean developers can create, merge and discard branches freely
- Can branch from any branch
- Can merge to any branch

Create a branch as a copy of the current branch
```
git branch <branch name>
```

Switch branch
```
git checkout <branch name>
```

Create a branch and switch to that branch
```
git checkout -b <branch name>
```

Comparing current branch to another
```
git diff <other branch>
```

Comparing two other branches
```
git diff <branch one> <branch two>
```

This can also be done in PyCharm and CLion.

## Merging and rebasing

Merging combined the history for the source branch with that of the target.

To merge a branch to the current working branch:
```
git merge <source branch>
```

Rebasing applies the changes from the branch after the changes from another

To rebase:
```
git rebase <other branch>
```

### Exercise 01.01
In your sandbox project experiment with branch and rebasing:
1. Create some branches
2. Commit different new files to each to the branches
3. Use both merging and rebasing
4. Observer how the git log looks after these changes

## Conflicts
The merge command shown earlier will fail if there are changes to the same files in both branches.
No fast forward merge and resolve conflicts
```
git merge <source branch>
```
Resolve the conflicts and use `git add` to mark as merged. Committing will apply the merge.

Rebasing your source branch may also solve or reduce the merge conflicts



## Branching Strategy
There are many complex branching strategies (see Git Flow for example). However, it is best to keep it simple.

"Trunk" Development: Keep the latest on master

## Feature branching
- Branch to develop a feature
- Keep features small
- Merge back to master as soon it is ready

![alt text](feature_branching.svg "The feature branching strategy")

## Release Branching
- Required only if multiple versions are to be maintain e.g 2.3.n and 3.0.n

61 changes: 61 additions & 0 deletions 08_code_management/02_Remotes_and_GitHub.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Remotes and GitHub

## Git Remotes
- A remote a is repository on a server that is tracked by the local repository
- Git is decentralised and can have multiple remote servers
- Local branches can be configured track remote branches
- Different branches can track different remotes

Adding a remote:
```
git remote add <remote name> <remote url>
```
Default remote name is `origin`

Push a branch to a remote branch
```
git push --set-upstream <remote> <upstream branch name>
```

pushing changes from local branch to remote branch
```
git push
```

pull changes from remote branch to local tracking branch
```
git pull
```

To make you local branch be aware of latest set of remote branches you will need to fetch from the remote

fetching branches and tags from remote
```
git fetch <remote name>
```
If fetching from remote called `orgin`
```
git fetch
```


## GitHub
- GitHub is a hosted Git Server at https://github.com
- Free account allow unlimited public and private projects. Though only 3 collaborates are permitted on private projects is restricted

### Exercise 02.01
1. Register a at github.com
2. Create a public repository for your project with BSE3 licence
3. Configure the remote and push master
4. Create a private repository for your sandbox
5. Configure the remote and push all branches

*Note:* You will be creating your repository with BSE3 licence.

## Cloning a existing Repository
```
git clone <url>
```

### Exercise 02.02
Create and new project in GitHub and clone it locally
86 changes: 86 additions & 0 deletions 08_code_management/03_README_and_Markdown.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# Living Documentation

## README
- Plain text file traditionally distributed with source to provide documentation on the software
- GitHub will display README files to the root of the project and any directories that contain them
- README files written in markdown (README.md) will be display as formatted HTML in GitHub
- These form part living documentation of the code as it can be update alongside the code the in code repository

## Markdown
A plain text readable format that can also be converted to HTML or displayed in other rich format

Headings
```markdown
# Top level heading

## Level two heading

### Level three heading

```


Bullets lists and numbered lists
```markdown
- Point 1
- Another point

1. The first item
2. Yet other item
```
- Point 1
- Another point

1. The first item
2. Yet other item

Note: Number list that are non-sequential will be displayed sequentially

Code blocks
````markdown
```python
def add_one(n):
return n + 1
```
````
```python
def add_one(n):
return n + 1
```
Tables
```markdown
|Name of Fruit |Price of Fruit|
|:-------------|-------------:|
|Orange |40p |
|Apple |20p |
|Banana |50p |
```
|Name of Fruit |Price of Fruit|
|:-------------|-------------:|
|Orange |40p |
|Apple |20p |
|Banana |50p |

*_Plus more!!!_*

## Exercise
Create a README file for your assignment providing a description of what the software will be written in markdown.

## Documentation comments
Many languages have built in support or tools for generating documentation or for provide help in IDEs.

Python has docstrings

```python
def add_one(n):
"""
Adds one to a number
:param n: The number one will be added to
:return: the number with one added
"""
return n + 1
```

Doxygen can be used to generate documentation for C and C++ (as well as many other languages)
### Exercise
Experiment with creating Doxygen (http://www.doxygen.nl) comments in C++
12 changes: 12 additions & 0 deletions 08_code_management/04_Pull_Request_and_Forking.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Pull Requests and Forking

## Pull request
- Pull requests are means are developers can collaborate by sharing and reviewing their changes.
- Pull requests can be crate from branches, forks and patches.
- Provide a means of peer reviewing and reviewing feature branches as they merge to master

## Forks
- Forking allows one to take a copy of project and makes changes with out effecting the original project
- Pull requests can be raise back to the original project

*Demonstration*
6 changes: 6 additions & 0 deletions 08_code_management/05_Issues.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# GitHub Issues

- Allow one to create a list of task that need to be done to deliver the softare
- Can be used to track features to be delivered
- Can be used to track defects in the software
- Allows other to raise defects and provide feature requests
Empty file.
Loading