Git documentation - Jibus22/webserv GitHub Wiki

git reminder ⏬

📖 Documentation

Docs & tutos

https://git-scm.com/docs
https://www.miximum.fr/blog/enfin-comprendre-git/
https://blog.lesieur.name/comprendre-et-utiliser-git-avec-vos-projets/

Cheat sheet

https://github.blog/2015-06-08-how-to-undo-almost-anything-with-git/
https://cheatography.com/samcollett/cheat-sheets/git/
https://rogerdudler.github.io/git-guide/
https://training.github.com/downloads/github-git-cheat-sheet.pdf

Workflow tutorials

https://zepel.io/blog/5-git-workflows-to-improve-development/
http://www.goring.org/resources/project-management.html
https://www.robinwieruch.de/git-team-workflow
🔽 below: naming conventions
https://opensource.com/article/19/2/emoji-log-git-commit-messages
https://dev.to/couchcamote/git-branching-name-convention-cch
https://codingsight.com/git-branching-naming-convention-best-practices/

🗒️ Notes

Commit message convention - proposal

<type>(<scope>): <subject>

✨feat: A new feature
🐛fix: A bug fix
📝docs: Documentation related changes
♻️refactor: A code that neither fix bug nor adds a feature. (eg: You can use this when there is semantic changes like renaming a variable/ function name)
⚡️perf: A code that improves performance
🎨style: A code that is related to styling
✅test: Adding new test or making changes to existing test
👓chore: A code change that external user won't see (eg: change to .gitignore file or .prettierrc file)


.

:electron: Reminder

🖼️ local git [areas]:

[working_dir]------(git add)------>[index(stage)]---------(git commit)--------->[head]
[working_dir]<-----(git reset)------[index(stage)]<--(git reset --soft HEAD~1)---[head]

💡 Tips

  • never git checkout <any_branch> with uncommited files in your actual branch
  • never directly work on develop branch
  • never git pull with uncommited files in your actual branch

📟 Monitoring

$ git remote -v    # tracked repositories
$ git branch -va   # Local & remote branches

$ git log          # commits History
$ git reflog       # HEAD History
$ git diff         # [staged]/[head (commited)] files differences
$ git status       # [unstaged]/[staged] files

🏡 Local work

$ git branch <branch_name>    # create new branch called <branch_name>
$ git checkout <branch_name>  # jump to <branch_name>
$ git branch -d <branch_name> # delete <branch_name>

$ git add *                   # add files to index area (see diagram)
$ git commit -m "message"     # add indexed files to head area (see diagram)
(feature)$ git merge develop  # merge develop branch into your actual feature branch (may have conflicts to resolve)

☁️ Remote work

$ git push <upstream> <branch> # push <branch> to your remote server <upstream>. ex: 'git push origin feature'
$ git pull <upstream>          # repatriate and integrate <upstream> data in your current branch. ex: 'git pull origin'

$ git remote prune origin      # deletes stale references associated with origin. With --dry-run option, report what branches would be pruned, but do not actually prune them.

⏰ Undo

Working dir area

$ git clean -i             # remove untracked files with interactive mode
$ git checkout -- <file>   # restore <file> to last index or head state (works only with tracked file)

Index area

$ git reset                # moves back files from index area to working directory area (undo git add)
$ git reset <file>         # same as above, but only with <file>

Head area

$ git reset --soft HEAD~1  # cancel & delete your last commit, going back to HEAD~1 state with your index area as before this last commit
$ git reset --hard HEAD~1  # cancel & delete your last commit & last index area, going back to HEAD~1 state.
$ git revert HEAD          # creates a new commit based on HEAD~1

$ git merge --abort        # abort the current conflict resolution process, and try to reconstruct the pre-merge state (work both within local merge or within remote merge)
⚠️ **GitHub.com Fallback** ⚠️