Git
Git is a distributed version control system that tracks changes in any set of computer files.
Cool thing to show star history:
Resources
- Advanced Git Tips for Python Developers
- https://onlywei.github.io/explain-git-with-d3/
- Interactive rebase— the ultimate git superpower
gh auth login
Git remove file that is already stored
git rm --cached -r <YOUR_files_or_folders>
Topics
Git Reset vs. Revert vs. Checkout reference
Commands
The git stash
command helps you stash your work away and clear your working directory. Then when you checkout it will not carry over the new code with you.
Lessons from Ericsson
Make your personal branch in a way that it can track the master:
- git checkout -b personal/$USER/pdcch origin/master
- git pull -r (to rebase)
- cherry pick: git fetch ssh://ezalwya@gerrit.ericsson.se:29418/lte/ebb refs/changes/04/12367804/1 && git cherry-pick FETCH_HEAD
gerrit ex: link, to download the patch, I see 4 options.
- repo download
- checkout
- pull
- cherry-pick
Checkout: Fetches the latest changes. You should already have this repo downloaded. It does not merge those new changes but makes your working directory reflect them. And a name-less commit is created to include these changes in your working directory. And a detached HEAD pointing to it. You can merge them at your leisure later.
Pull: Fetches the changes AND merges them into the local branch of the same name.
Cherry-pick: Fetches the commit and plays it on top of the current local branch, thus creating an entirely new commit which happens to have same changes as the one it fetched.
Useful Tips
- Setup your
~/.gitconfig
so you can use shortcuts. I have my own.gitconfig
file so typing commands is faster.
NEW: Since joining Ericsson, I’ve realized that it is even more productive to exclude the space. However, to do that, the aliases need to be written in the shell, i.e. ~/.zshrc
instead of ~/.gitconfig
For instance,
Alias | Command |
---|---|
ga | git add |
gb | git branch |
gbv | git branch -vv |
gcm | git commit -m |
gs | git status |
gp | git push |
gst
ga .
gcm "insert message"
gps
- What do you do if you just made a commit but then realize that
flake8
has an error when you run it? Or you spot a typo in the commit message you just entered? Git will allow you to “amend” a commit:
g cm --amend "I am bad at spelling"