GIT workshop (15-20 min)
Fran García-Linares
December 2017
Agenda
1
2
3
4
5
Git and GitHub
Workflow practices (branching, PRs, merging, etc)
Issues when working with other people (aka git conflicts)
Issues when working with multiple branches (permissions, changed files, etc)
Q & A
Git
- Basically this means console
- Documentation: here
- You can survive with:
- git status
- git add / commit
- git commit -am "..."
- git pull / push / merge
- git checkout
- Others
- D7 => (git submodule)
- git stash
- There is lots of extra info, good practices, naming conventions, etc in confluence: here
- NOTE: MacOS file system is case insensitive (issues with branch names...)
GitHub
- This means the Github UI.
- It's just a remote place to store our git repos (alternatives: bitbucket, gitlab, codebase, drupal, etc)
- Useful to:
- Define repo permissions
- Review code (via PRs)
- Create branches? (more later)
- Not useful to:
- Resolve conflicts (I will never ever use -again- github to solve any merge conflicts)
Useful hack for MacOS
- Have git branch on your prompt
- Sometimes git branch fails to recognise current branch)
- nano ~/.bash_profile (append the below snippet)
- source ~/.bash_profile
# Git branch in prompt.
parse_git_branch() {
git symbolic-ref HEAD 2> /dev/null | sed -e 's/^refs\/heads\///g' -e 's/^/ \(/' -e 's/$/\)/'
}
RESET="\[\017\]"
NORMAL="\[\033[0m\]"
YELLOW="\[\033[33;1m\]"
export PS1="${RESET}${NORMAL}\u@MacBookPro :: \w${YELLOW}\$(parse_git_branch) ${NORMAL}$ "
Workflow practices (branching, PRs, merging, etc)
- Branching
- Creating new branches
- Via Github (UI + git pull + git checkout...)
- Via console (git checkout prod + git checkout -b... + git push -u...)
- Creating new branches
- PRs
- Via github
- Via console: git request-pull
- Merging
- Merge prod into your branch regularly (if working on big tickets)
-
git checkout prod && git pull
-
git checkout BRANCH && git merge prod
-
- Merge prod into your branch regularly (if working on big tickets)
- Delete merged branches
- After merging to prod it's good practice to delete the branch
- git branch -a (shows all branches, local & remote)
- Do this from github, it can always be recovered if needed
Issues when working with other people (aka git conflicts)
- Don't use github resolving tool / commands
- It will try to solve it AND push changes (probably to the least expected branch...)
- If you have a git conflict (the PRs has some conflict merges)
- Identify where the error is (you can use the github tool for this or merge manually on your local)
- Common:
- .gitmodules (move module to the middle of the file)
- CSS (recompile css and ignore older version)
- Check code and see what the conflict is
- Sometimes both parts of the conflict are valid
- Sometimes only one part is valid
- Sometimes a mix of the parts is the valid resolution
- Best solution for these is to "talk" to the other person if you're not sure of the resolution
- Common:
- Identify where the error is (you can use the github tool for this or merge manually on your local)
Issues when working with multiple branches (permissions, changed files, etc)
- Issues when changing branches
- File permissions
- Mostly due to Drupal
-
chmod 777 sites/default
- Uncommitted changes
- Ignore and be careful
-
git stash / git stash pop
- Git submodules folders
- Ignore and be careful
-
rm -rf path/to/folder
-
gm*
- When switching back to branch with those modules
- Others: slack!
- File permissions
* Alias list. Similar to:
git submodule update --init + git submodule sync
Q & A
INTERNAL // GIT workflows and issues - workshop
By Fran García-Linares
INTERNAL // GIT workflows and issues - workshop
- 1,386