Git - Tips and Tricks
@kenji_lozano
@kenji_lozano
Kenji Lozano
Senior Software Developer, Truextend
Angular, React and Java Lover
Javascript Lover
Sucre, Bolivia
Cochabamba
Spring, .NET
Wait... Hey! You're an Angular Lover!
Question....
What is the difference between...?
Service
Service
Tool
TIP 01
The CLI is our BEST FRIEND
That means...
Jorge dile algo!!
Vete a la f*kiu
omaiga enserio!?
Pero hay un Dios
que todo lo ve.
ya cag*eishon
So...
TIP 02
We MUST understand what is the branching model
Branching Model
Decentralized but centralized
The Main Branches
Supporting Branches
Feature Branches
$ git checkout -b myfeature develop
# Switched to a new branch "myfeature"
Creating a feature branch
$ git checkout develop
# Switched to branch 'develop'
$ git merge --no-ff myfeature
# Updating ea1b82a..05e9557
# (Summary of changes)
$ git branch -d myfeature
# Deleted branch myfeature (was 05e9557).
$ git push origin develop
Merge feature to develop
Feature Branches
What does --no-ff?
Release Branches
$ git checkout -b release-1.2 develop
#Switched to a new branch "release-1.2"
$ git commit -a -m "Bumped version number to 1.2"
#[release-1.2 74d9424] Bumped version number to 1.2
#1 files changed, 1 insertions(+), 1 deletions(-)
$ git commit -m "Some release commit"
Creating a release branch
Release Branches
$ git checkout master
#Switched to branch 'master'
$ git merge --no-ff release-1.2
#Merge made by recursive.
#(Summary of changes)
$ git tag -a 1.2
Merge release branch to master
$ git checkout develop
#Switched to branch 'develop'
$ git merge --no-ff release-1.2
#Merge made by recursive.
#(Summary of changes)
Merge release branch to develop
Hotfix Branches
$ git checkout -b hotfix-1.2.1 master
# Switched to a new branch "hotfix-1.2.1"
$ git commit -a -m "Bumped version number to 1.2.1"
#[hotfix-1.2.1 41e61bb] Bumped version number to 1.2.1
# 1 files changed, 1 insertions(+), 1 deletions(-)
# ...
$ git commit -m "Fixed severe production problem"
# [hotfix-1.2.1 abbe5d6] Fixed severe production problem
# 5 files changed, 32 insertions(+), 17 deletions(-)
Creating a hotfix branch
Hotfix Branches
$ git checkout master
# Switched to branch 'master'
$ git merge --no-ff hotfix-1.2.1
# Merge made by recursive.
# (Summary of changes)
$ git tag -a 1.2.1
Merge hotfix branch to master
$ git checkout develop
# Switched to branch 'develop'
$ git merge --no-ff hotfix-1.2.1
# Merge made by recursive.
# (Summary of changes)
Merge hotfix branch to develop
Don't worry if you have some doubts. We plan to do a live ...
TIP 03
Write GOOD git commit message!
Commit Message
The most common mistake is that a bunch of developers DON'T KNOW how to write a proper commit message
Kenjis-MacBook-Pro:website kenji$ git log --pretty=oneline --abbrev-commit
#cd3e27a contact page
#aee9d0d comments
#eac95e5 list of online users, some other changes because of server
#fae5636 little edit
#fae5636 feature now working
#fae5636 i completed the task
Kenjis-MacBook-Pro:website kenji$ git log --pretty=oneline --abbrev-commit
#43ec6aa Fix error when the URL is not reachable
#4fe84ab Add error message if something went wrong
#753aa05 Add server fingerprint check
#df3a662 Fix shadow box closing problem
Commit Anatomy
[TICKET_ID | Optional | N/A] Fix error when protocol is missing
First, it checks if the protocol is set. If not, it changes the url and
add the basic http protocol on the beginning.
Second, it does a "preflight" request and follows all redirects and
returns the last URL. The process then continues with this URL.
Resolves #17
Subject
Body
Bottom Line
How to write a good commit message
[TICKET_ID | Optional | N/A] Fix error when protocol is missing
.
.
.
it very good as a single short (less than 50 character) line summarizing the change, followed by a blank line
"If applied, this commit will (has been)... [commit]" Rule
-
if applied, this commit will Delete unnecessary files
-
if applied, this commit will Add grep option
-
if applied, this commit will Fix error when protocol is missing
-
if applied, this commit will contact page
-
if applied, this commit will I completed the task
How to write a good commit message
...
First, it checks if the protocol is set. If not, it changes the url and
add the basic http protocol on the beginning.
Second, it does a "preflight" request and follows all redirects and
returns the last URL. The process then continues with this URL.
Resolves #17
Body
Bottom line
The body should not exceed 72 characters for a line. Of course not every commit has to have body.
This can be a link, number or if you use GitHub you can write it as Resolves #N / Closes #N, where N is the issue ID.
Commit Recipe
$git commit -m
"[TICKET-ID] [Verb(past|present) - Quick description]"
where: ...
[TICKET-ID]: Is your task id. I.E: III-123, Tsk-12, N/A
Verb(past|present): Is the action that you make. I.E: Implemented, Fixed, Updated.
Quick description: Describe your changes. I.E: users list component
$git commit -m "[III-123] Implemented users list component"
TIP 04
Setup your user-name and user-email properly!
Setup your Git Env
Another common mistake is that a bunch of developers don't have a proper git configuration
Kenjis-MacBook-Pro:website kenji$ git log
commit 0e3240cbd4f6501a827255f4cbeb00966a284e2c (HEAD -> bugfix/III-13714, origin/bugfix/III-13714)
Author: Juan Perez <juan.perez@truextend.com>
Date: Thu Aug 15 17:35:12 2019 -0400
[III-13714] Added missing tabindex values
commit 8fdf829efa156ba45fded4cfcc6d7786e62eb3fb (origin/develop_3.2, develop_3.2)
Author: John Perez <elsexymachocaporal@gmail.com>
Date: Wed Aug 14 13:10:14 2019 -0500
Merge pull request #4157 in I3/website from bugfix/III-13709 to develop_3.2
commit 0e3240cbd4f6501a827255f4cbeb00966a284e2c (HEAD -> bugfix/III-13714, origin/bugfix/III-13714)
Author: John Perez <elsexymachocaporal@gmail.com>
Date: Thu Aug 15 17:35:12 2019 -0400
[III-13714] Added missing tabindex values
commit 8fdf829efa156ba45fded4cfcc6d7786e62eb3fb (origin/develop_3.2, develop_3.2)
Author: John Perez <elsexymachocaporal@gmail.com>
Date: Wed Aug 14 13:10:14 2019 -0500
Merge pull request #4157 in I3/website from bugfix/III-13709 to develop_3.2
Setup your Git Env
It's easy to avoid that embarrassing commits
Kenjis-MacBook-Pro:test kenji$ git config user.name "Kenji Lozano"
Kenjis-MacBook-Pro:test kenji$ git config user.email "Kenji@domain.com"
Or... You can edit .git/config manually
Kenjis-MacBook-Pro:test kenji$ cat .git/config
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
ignorecase = true
precomposeunicode = true
[user]
name = Kenji Lozano
email = Kenji@domain.com
TIP 05
Git docs are the source of truth
Git Docs
Repeat after me: "Git Docs is my best friend"
$ git help [-a|--all [--[no-]verbose]] [-g|--guide]
[-i|--info|-m|--man|-w|--web] [COMMAND|GUIDE]
Git Docs
Repeat after me: "Git Docs is my best friend"
What about tricks?
Let's have some sort of Coding Dojo!
What is Coding Dojo?
A Coding Dojo is a meeting where a bunch of coders get together to work on a programming challenge.
Coding Dojo
Characteristics
Non-competitive, collaborative, fun environment
All skill levels are welcome
Safe to try new ideas
Requirements
Meeting room with enough seats (typical attendance varies between 5 and 20 ?)
At least one PC or laptop
A digital projector (‘beamer’)
Today's Coding Dojo is a git-based Kata(Challenge), in order to play with Git.
Let's type some Git commands...
Rule: Kenji won't be able to touch the keyboard
Resources
https://nvie.com/posts/a-successful-git-branching-model/ https://sethrobertson.github.io/GitBestPractices/ https://raygun.com/blog/git-workflow/ https://juffalow.com/other/write-good-git-commit-message https://medium.com/@steveamaza/how-to-write-a-proper-git-commit-message-e028865e5791 https://medium.com/quick-code/top-tutorials-to-learn-git-for-beginners-622289ffdfe5 https://www.atlassian.com/git/tutorials/advanced-overview https://github.com/git-tips/tips https://git-scm.com/book/en/v1/Git-Basics-Tips-and-Tricks https://about.gitlab.com/2016/12/08/git-tips-and-tricks/ https://www.algotech.solutions/blog/engineering/git-tips-tricks/
Kenji's experience.....
And...
Thank You!
Hope you enjoyed this talk!
Git - Tips and Tricks
By Kenji Lozano
Git - Tips and Tricks
Let's review a few useful commands.
- 159