Git

Git

Git is niet het meest eenvoudige broncode versiebeheersysteem. Het is echter wel het meest gebruikte en geavanceerde versie beheersysteem. Verder is het zeer effcient omdat het werkt met snapshot hashes.

Git workflow feature branch

Je kunt met git op vele manieren werken, een veel gebruikte variant is de workflow feature branch. Clone een bestaande git repository.

git config --global user.name "user"
git config --global user.email "user@git.opene.nl"
git clone https://git.opene.nl/user/test.git
cd test

Welke branches zijn er?

git branch
* master

Maak een nieuwe feature branch aan.

git checkout -b branch1

Maak wijzigingen op de feature branch. Zijn er wijzigingen?

git status

Files toevoegen voor commit.

git add .

Commit de wijzigingen.

git commit -m "New feature b1"

Push de branch naar de remote repo.

git push -u origin branch1

Checkout master.

 git checkout -f master

Merge branche met master.

git merge --no-ff branch1 master

Push naar remote repo.

git push -u origin master

Bekijk de workflow.

git log --graph --oneline --branches --all
*   e2521f4 (HEAD -> master, origin/master) Merge branch 'branch1'
|\
| * 6d98269 (origin/branch1, branch1) New feature b1
|/
* 07eb4a7 add README

Na de merge kan de feature branch worden verwijderd.

git checkout master
git branch -d branch1

Verwijder de remote branch.

git push origin --delete branch1

Git nieuwe branch op bestaande branch

Checkout branch branch1

git checkout branch1
git branch
* branch1
  master

Maak een nieuwe branch aan.

git checkout -b branch1-1 branch1
Switched to a new branch 'branch1-1'
git branch
  branch1
* branch1-1
  master

Pas code aan en commit.

git add .
git commit -m "commit branch1-1 patch"
[branch1-1 2dcd2cc] commit branch1-1 patch
 1 file changed, 2 insertions(+)

Push naar remote repo.

git push -u origin branch1-1

Checkout branch1.

git checkout -f branch1

Merge branch1-1 op branch1

git merge --no-ff branch1-1 branch1
Merge made by the 'recursive' strategy.
 branch1-file | 2 ++
 1 file changed, 2 insertions(+)

Push naar remote repo.

git push -u origin branch1

Checkout master.

git checkout -f master

Merge branch1-1 op branch1

git merge --no-ff branch1 master
Merge made by the 'recursive' strategy.
 branch1-file | 2 ++
 1 file changed, 2 insertions(+)

Push naar remote repo.

git push -u origin master

Bekijk de workflow.

git log --graph --oneline --branches --all
*   6133ce5 (HEAD -> master, origin/master) Merge branch 'branch1'
|\
| *   6ec68e4 (origin/branch1, branch1) Merge branch 'branch1-1' into branch1
| |\
|/ /
| * 2dcd2cc (origin/branch1-1, branch1-1) commit branch1-1 patch
|/
*   e2521f4 Merge branch 'branch1'
|\
| * 6d98269 New feature b1
|/
* 07eb4a7 add README