Global Config
git config --global user.name "FirstName LastName"
git config --global user.email youremail@domain.extension
Command line, code, etc
- Global Informations
Project Structure branches by convention
Required :
- master
- develop
Extra :
- feature-xxx
- release-xxx
- hotfixes-xxx
Convention name for versionning
1.0.0-alpha < 1.0.0-alpha.1 < 1.0.0-alpha.beta < 1.0.0-beta < 1.0.0-beta.2 < 1.0.0-beta.11 < 1.0.0-rc.1 < 1.0.0
Clone your project
git clone git@github.com:yourrepo/yourprojectname.git
Clone your project without all history
git clone --depth 1 git@github.com:yourrepo/yourprojectname.git
Where my code is stored, basicaly is just one remote, orgin. But you could have more than one remote with on each more than one branch....
git remote -v
- How to commit
First you have to select the branch
git checkout develop
After add new file to your local git git add . git commit -am "Add, Fix "
Then send your code to remote directory
git push origin develop
If you want compare two branch git diff <source_branch> <target_branch>
- How to manage tag
List all tags on the repo
git tag
Add new tag on a branch
git tag -a 1.0.0-alpha -m 'the initial release'
git push origin --tags
This command if you dont have information, tag will be automaticaly generated by git. git push origin : tempTag
- How to manage branch - global
First, you have to check all informations about your branch
git branch -a
Go to a branch
git checkout [name_of_your_new_branch]
Add a new branch
git branch [name_of_your_new_branch]
git branch master
git branch develop
Add a new branch and jump it
git checkout -b [name_of_your_new_branch]
Merge a branch
git checkout branch-orgine
git merge --no-ff new-branch
Using --no-ff, means that you keep information about this branch even after delete
Remove a branch
git branch -d branch
- Manage branch - Feature (only develop branch)
So first, you have to create a new branch. By convention, feature-xxx (xxx means version number like 1.2)
git checkout -b feature-xxx develop
When your modifications are over, merge push and delete this temporary branch
git checkout develop
git merge --no-ff feature-xxx
git branch -d feature-xxx
git push origin develop
- Manage branch - Release (master or dev branch)
This branch is usefull to manage versioning on your apps.
So first, you have to create a new branch. By convention, release-xxx (xxx means version number like 1.2)
git checkout -b release-xxx
When your modifications are over, merge push and delete this temporary branch
bump-version.sh xxx
git commit -a -m "Bumped version number to xxx"
git checkout master
git merge --no-ff release-xxx
git tag -a xxx 'the Release xxx with ....'
git checkout develop
git merge --no-ff release-xxx
git branch -d release-xxx
bump-version.sh is a file using to set the version number on your app (add code on readme and add tag)
- Manage branch - Hotfix (master or dev branch)
This branch is usefull to fix fastly some critical bug for production.
So first, you have to create a new branch. By convention, hotfix-xxxX (xxxX means version number like 1.2.1)
git checkout -b hotfix-xxxx
When your modifications are over, merge push and delete this temporary branch
git checkout -b hotfix-1.2.1 master
./bump-version.sh 1.2.1
git commit -a -m "Bumped version number to 1.2.1"
git commit -m "Fixed severe production problem"
git checkout master
git merge --no-ff hotfix-1.2.1
git tag -a 1.2.1 -m 'the Hotfix 1.2.1 with ....'
git checkout develop
git merge --no-ff hotfix-1.2.1
git branch -d hotfix-1.2.1
- Manage branch with git-flow
First install command line on your computer :
brew install git-flow
Add this command on your git project :
git flow init
Feature
git flow feature start MYFEATURE
git flow feature finish MYFEATURE
git flow feature publish MYFEATURE
git flow feature pull origin MYFEATURE //get a feature from repo
Release
git flow release start RELEASE [BASE]
git flow release publish RELEASE
git flow release finish RELEASE
Hotfixes
git flow hotfix start VERSION [BASENAME]
git flow hotfix finish VERSION
Examples with 2 branchs :
A---B---C mes_devs [HEAD]
/
D---E---F---G master
If I use a merge commande I will have :
A---B---C
/ \
D---E---F---G---H master mes_devs [HEAD]
git rebase master
A---B---C mes_devs [HEAD]
/
D---E---F---G master
git checkout master git merge mes_devs
A---B---C mes_devs master [HEAD]
/
D---E---F---G