Skip to content

Commit

Permalink
Update Git basics and how I work with Git (#186)
Browse files Browse the repository at this point in the history
* Update Git basics and how I work with Git

* Add link to bash PS1 trick

* Fix linting
  • Loading branch information
uekerman authored Oct 15, 2024
1 parent cdfb5d2 commit b6ec0a8
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions 01_version_control/git_basics_demo.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,31 +37,31 @@ Starting remarks:
- fork -> my fork

- (2) Working directory:
- ZSH shell shows git branches
- ZSH shell shows git branches. There are [similar solutions for Bash](https://coderwall.com/p/fasnya/add-git-branch-name-to-bash-prompt) as well.
- `git remote -v` (I have upstream, myfork, ...)
- mention difference between ssh and https (also see GitHub)
- get newest changes `git pull upstream develop`
- or simply `git pull` (`git branch -vv` to see upstream tracking)
- `git log` -> I use special format, see `~/.gitconfig`,
- check log on GitHub; explain short hash
- `git branch`
- `git branch add-demo-feature`
- `git checkout add-demo-feature`
- check log on GitHub
- explain how hash is computed (complete state + pointer to parent)
- explain short hash
- `git checkout -b add-demo-feature`

- (3) First commit
- `git status` -> always tells you what you can do
- `vi src/action/Action.hpp` -> add `#include "MagicHeader.hpp"`
- `git diff`, `git diff src/com/Action.hpp`, `git diff --color-words`
- `git status`, `git add`, `git status`
- `git commit` -> "Include MagicHeader in Action.hpp"
- `git status`, `git log`, `git log -p`, `git show`
- `git status`, `git log`, `git show`

- (4) Change or revert things
- (4) Change or reset things
- I forgot to add sth: `git reset --soft HEAD~1`, `git status`
- `git diff`, `git diff HEAD` because already staged
- `git log`
- `git commit`
- actually all that is nonsense: `git reset --hard HEAD~1`
- modify again, all nonsense before committing: `git checkout src/action/Action.hpp`

- (5) Stash
- while working on unfinished feature, I need to change / test this other thing quickly, too lazy for commits / branches
Expand All @@ -70,7 +70,6 @@ Starting remarks:

- (6) Create PR
- create commit again
- preview what will be in PR: `git diff develop..add-demo-feature`
- `git push -u myfork add-demo-feature` -> copy link
- explain PR template
- explain target branch
Expand All @@ -87,13 +86,17 @@ Starting remarks:
- `git checkout -t alex/[branch-name]`
- I could now also push to `ajaust`'s remote

- (8) GitHub CLI
- `git push -u ...` and `git pull -t ...` maybe hard to remember at first.
- Things get easier with the [GitHub CLI](https://cli.github.com/), but bound to GitHub, obviously.

## Further reading

### Quick things

- [Video: Git in 15 minutes: basics, branching, no remote](https://www.youtube.com/watch?v=USjZcfj8yxE)
- [The GitHub Blog: Commits are snapshots, not diffs](https://github.blog/2020-12-17-commits-are-snapshots-not-diffs/)
- Chapters [6](https://merely-useful.tech/py-rse/git-cmdline.html) and [7](https://merely-useful.tech/py-rse/git-advanced.html) of Research Software Engineering with Python
- Chapters [6](https://third-bit.com/py-rse/git-cmdline.html) and [7](https://third-bit.com/py-rse/git-advanced.html) of Research Software Engineering with Python
- [Podcast All Things Git: History of VC](https://www.allthingsgit.com/episodes/the_history_of_vc_with_eric_sink.html)
- [git purr](https://girliemac.com/blog/2017/12/26/git-purr/)

Expand Down

0 comments on commit b6ec0a8

Please sign in to comment.