2024-12-11
@username insteadDid people remember the conflicts-homework? How was that?
git diffWe’ll go through the list of some interesting issues:
https://github.com/nitwit2gitwit/recipes-2024/issues?q=label%3Ainteresting-to-discuss-next-lesson+
Very good! Way too often people just ignore warnings. It’s like warnings in real life:
It’s OK to ignore the ⚠️ this product contains peanunts or ⚠️ the contents of this cup are hot warning if you understand what they mean. If you see a ⚠️ ゴジラ破地区, it’s probably time to look for a dictionary before you go on.
In CS/code the reason to fix your warnings is:
(actually this was also the main issue with the 🥕🥕🥕)
A=0x41..Z=0x5A, a=0x61…z=0x7a, 0=0x30..9=0x39Latin-1, Latin-2, Latin-3, Latin-4, Cyrillic, Arabic, each having different encodings for 127-255.git (through git config set --global ...)git has no security (I can set mine to “Elon Musk/elon@tesla.com” and no checks are made)
git has a system of signing your commits, but normal people don’t do thatgit email address and GitHub email address are not the same, you will get some message on GitHub.git status (to avoid forgetting an image)/site/).Rhistory).DS_Store).gitignore so that you know not the check them in / will still see missed filesA fork is a new repository that shares code and visibility settings with the original “upstream” repository.
A fork allows you to make changes in a repository, without the original owner being involved:
Note that 1 and 2 produce a long-lived fork, while 3 & 4 are short-lived forks (usually)
Usually a fork is made if you don’t have write access to the repo, but it doesn’t have to be.
Using git:
git clone https://github.com/username/reponame
git remote remove origin
git remote add origin https://github.com/yourusername/yourreponame
git pushHowever much easier to use GitHub UI (just press “Fork” button”). Now GitHub knows that it’s a fork (and allows you to stay up to date) / make a PR.
Playtime
Everyone creates a fork of the nitwit2gitwit repository.
Note the extra UI of the fork.
Forking and Starring
Note that if you want to keep track of a repo, you may also star ⭐ it. Both stars and fork counts help others see how popular a repo is. And if you choose a tool to use, you probably would prefer the more popular one.
Also be aware not to confuse a forked repo for the original – although sometimes you need the fork
In a Pull Request (PR) you request someone else to pull in (or merge) your changes.
main) in a fork that has some commits that are not in the target branch (usually main).Note
A PR can be as little as a single character (typo, bug in code), or as big as a full rewrite of all files in the repo.
Your PR will have most chance to be accepted if it deals with a single issue. A PR saying “I fixed these 5 bugs, and also added some documentation and fixed some typos” is less likely to succeed (unless they all had a common cause).
Pay attention
The final homework will be about making a PR and getting it accepted
Playtime
Make a PR towards the nitwit2gitwit repo
git in RStudioRStudio has a built in git client. It’s 100% compatible with the commandline git client. You can freely switch between one and the other.
Git tab in Rstudio
Playtime
git log | head -n 20 in cli (in the recipes-2024 dir)pull in Rstudiogit log | head -n 20 in cli (in the recipes-2024 dir)git statusgit statusgit revert, then by resetting`git resetgit reset changes the commit that the current branch points to.
git reset 00ac05 means “make the current branch point to 00ac05git reset --hard 00ac05 does the same, but also checks out the new code)git reset branch1 means “make the current branch point to whatever branch1 points to nowgit reset HEAD~1 means “make the current branch point to the parent of HEAD”git reset HEAD~2 means “… to the parent of the parent of HEAD”, etc.git reset origin/main means “make the current branch point to whatever was the main branch on origin, last time we fetched (or: remove all local commits)Warning
This is one of those “with great power….” commands. Where normally git only allows you to add new info (never permanently delete something that was committed before), git reset does have the power to make existing commits orphans (and schedule them for deletion).
At least as long as you don’t do git push -f, everything on GitHub will be safe.
git / more commandsWe only brushed the surface of git commands. There are commands to
git restore)git restore --staged)git commit --amend) – only do this if not pushed yetgit bisect)git submodule add)git stash)Note
When you git clone a repo, by default the submodules are not cloned. Sometimes you see instructions to run git submodule update --init --recursive after a clone – this is to install all submodules as well.
Google/ChatGPT is your friend, however, be safe:
push -f)git is just a directory in your working directory. If you want to try something scary, just make a copy of the whole directory cp -r myrepo myrepo2 and experiment. If it works, you can even directly push from myrepo2 and pull again in myrepo.git reset and lose some important commits), don’t panic. git will only remove orphans after a while, if you run git in that directory. So, first thing to do, make a backup (zip the whole directory). Once you have this, you can always send this zipfile to a smart person and they can probably recover your work.--force or --hard) should not remove any code.Homework for the coming weeks (we will discuss progress next week):