Do you like time travel? You should love git!
git basic, and most used commands
clone / init / pull / push / checkoutlog / status / merge / reset
git merge ⚡ git rebase
Git Merge- Simple and familiar.- Preserves complete history and chronological order.- Maintains the context of the branch.
Git Rebase- Streamlines a potentially complex history.- Avoids merge commit “noise” in busy repositories.- Cleans intermediate commits by making them a single commit. (interactive)
use git aliases
git config --global alias.co checkout git config --global alias.br branch git config --global alias.ci commit git config --global alias.st status git config --global alias.sw switch git config --global alias.re restore git config --global alias.visual '!gitk' # Go to root of the repository alias cdg='cd $(git rev-parse --show-toplevel)' # Add everything and ammend last commit alias ameno='cdg && git add . && git ci --am --no-edit' # Push everything to origin in last commit alias anarchy='ameno && git push --force-with-lease'
remotes / git is a distributed system
# Add a new remote git remote add origin firstname.lastname@example.org:iamandrewluca/voluntar-web.git # Removes the remote with upstream name git remote remove upstream # Rename upstream remote in origin git remote rename upstream origin # List all remotes git remote -v
196a829 refactor: replace zone title pipe with translate pipe 74313af refactor: replace special conditions constants with l10n bb74f05 feat(volunteers): refactor volunteers list (#194) d5a1336 feat: add Zone coords, deprecate old "enums" (#193) de5ff39 feat(demands): updated new demands form component (#188) ecab94e chore(deps): bump socket.io from 2.3.0 to 2.4.1 d201c37 feat(users): add user detail page ee56a19 fix(users): remove password from user edit when is empty ee11d45 chore: sync all languages when default was changed
Merging Pull Requests
🚀 Create a merge commit 🚀 Squash and merge 🚀 Rebase and merge what to do with big PR's?
git reflog the saviour
This means someone also pushed into this branch on origin remote. Activate this config.
Merge remote-tracking branch 'origin/main' into main
git config --global pull.rebase true
rebase instead of merging your local commits with commits that are already on origin
Rerere is an abbreviation for "reuse recorded resolution".
rerere is a feature that will memorize all resolved conflicts, and resolve them automatically if happens to encounter them in the future.
Enable the feature
git config --global rerere.enabled true git config --global rerere.autoupdate true
Now when you sync your feature branch with
merge, you resolve any conflicts you encounter, how many times you want (this works well with long living branches). In the end you see your feature branch history with all merge commits. You run once,
git rebase main and git will stop again at each commit that had conflicts, but the commit is already resolved, you just run
git rebase --continue . When
rebase is finished, poof, no merge commits, linear history.
In the last version of git,
checkout was split in 2 new commands,
restore , this was done because
checkout had too much responsibility
git switch -c some-new-branch-name git switch main git restore --source main path/to/some/file
Git minus operator (couldn't find any official docs)
# We are on long branch named feature/ABC-123-long-branch-name git switch main git pull git switch - git rebase -
In this context
- will be the previous branch
GitHub offers a big list of git ignore files for different occasions http://github.com/github/gitignore
Also they recommend to include in your local
.gitignore file only files related toy your project, no system generated files, no IDE files. Exclude them globally in your whole system.
fetch.prune config to true, this way, when any fetches are made, git will report any remotes branches that were removed.
git config --global fetch.prune true
BFG Repo-Cleaner. If you have a repository that weights a lot, you can scan it with BFG Repo-Cleaner, and it will report, and help you to get rid of big files in the repository, that are long time no needed but keep space.