version control, for beginners
$ git init
final-v2?$ ls ~/projects
project/
project-revised/
project-final/
project-final-FINAL/
project-final-real/
project-final-real-2/
Git is not the only one. It is just the winner:
CVS · Subversion · Mercurial · TFS ·
Perforce
A commit is a point. A branch is just a name pointing at one.
git pull = git fetch + git merge
git initgit clone <url>git statusgit loggit add <file>git add .git commit -m 'message'git branch <branch-name>git checkout <branch-name>git checkout -b <branch-name>$ git log --oneline
a1b2c3d created main loop & timing control
4d5e6f7 enabled config file parsing
8a9b0c1 misc bugfixes
2d3e4f5 code additions/edits
6a7b8c9 more code
0d1e2f3 here have code
4a5b6c7 aaaaaaaa
8d9e0f1 adkfjslkdfjsdklfj
2a3b4c5 my hands are typing words
Write for the person reading this in six months.
It will probably be you, and you will not remember.
add the file to mark it resolved,
and commit to finish the merge<<<<<<< HEAD (current change) readFileAndGenerating(file, split); ======= readFileAndGenerate(input, split); >>>>>>> main (incoming change) i18nFileGenerate(output, options || null);
Delete the markers. Keep the code you want — maybe both, maybe neither. VS Code puts buttons on top of exactly this.
git merge <branch>git merge --abortgit add <file>git commit$ git merge --abort
Nothing is lost — you are back exactly where you were before the merge.
First question: where is the change right now?
Reset what only you have. Revert what everyone has.
git restore <file>git restore --staged <file>git commit --amendgit reset --soft HEAD~1git revert <commit>git stashgit stash pop$ git reset --hard
The one undo you cannot undo: uncommitted changes are gone for good.
first time
$ git clone the address below
$ cd attendance
back again
$ cd attendance
$ git pull
then sign in
$ echo "Your Name" > your-name.txt
$ git add your-name.txt
$ git commit -m "your-name is here"
$ git push
Push rejected? Someone pushed first. Run git pull --rebase, then git push again.
0 signed in · connecting…
https://playground.hackenshaw.com/git/attendance.git
git checkout maingit
pullgit checkout -b
feature/add-logingit add .git commit -m "Add login
form"git checkout maingit merge
feature/add-logingit branch -d feature/add-logingit checkout maingit
pullgit checkout -b
feature/add-logingit add .git commit -m "Add login
form"git fetch origingit rebase
origin/maingit checkout maingit merge --ff-only
feature/add-logingit pushgit branch -d feature/add-logingit checkout maingit
pullgit checkout -b
feature/add-logingit add .git commit -m "Add login
form"git push origin
feature/add-loginmaincompare branchfeature/add-logingit fetch origingit
merge origin/maingit pushgit branch -d feature/add-logingit push origin
--delete feature/add-login| notes.txt | today's handout — everything we covered, in one text file |
| learngitbranching.js.org | branches and merges, drawn as you type them |
| ohmygit.org | an actual game about learning Git |
| ohshitgit.com | how to undo the thing you just did |
| w3schools.com/git | a click-through tutorial from zero |
| git-scm.com/book | Pro Git — the reference, free online |
And the one already on your machine: git help <command>.
$ open
presentations.hackenshaw.com/
These slides, with a link to
notes.txt.
$ thanks for coming