%23%20%2F%2F%2F%20script%0A%23%20requires-python%20%3D%20%22%3E%3D3.11%22%0A%23%20dependencies%20%3D%20%5B%22marimo%3E%3D0.23.9%22%5D%0A%23%20%2F%2F%2F%0A%0Aimport%20marimo%0A%0A__generated_with%20%3D%20%220.25.2%22%0Aapp%20%3D%20marimo.App(width%3D%22medium%22)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%20Version%20control%20with%20Git%20and%20GitHub%0A%0A%20%20%20%20%3E%20Marcos%20Duarte%2C%20Renato%20Naville%20Watanabe%3Cbr%3E%0A%20%20%20%20%3E%20%5BLaboratory%20of%20Biomechanics%20and%20Motor%20Control%5D(https%3A%2F%2Fbmclab.pesquisa.ufabc.edu.br%2F)%3Cbr%3E%0A%20%20%20%20%3E%20Federal%20University%20of%20ABC%2C%20Brazil%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20How%20to%20use%20this%20guide%0A%0A%20%20%20%20You%20corrected%20an%20equation%20in%20a%20notebook%20last%20week.%20Today%20you%20need%20to%20explain%20what%20changed%20and%20recover%20the%20earlier%20version.%20Git%20records%20that%20history%20locally%3B%20GitHub%20can%20host%20a%20shared%20copy.%20This%20guide%20teaches%20the%20small%20workflow%20needed%20for%20text-based%20Marimo%20notebooks.%0A%0A%20%20%20%20Read%20the%20examples%20in%20order%2C%20predict%20each%20result%2C%20and%20then%20run%20the%20cell.%20Try%20the%20distributed%20Exercises%20before%20opening%20their%20worked%20solutions.%20Finish%20with%20the%20checkpoint%20questions%20and%20independent%20Problems%3B%20their%20panels%20contain%20final%20answers%20only.%0A%0A%20%20%20%20**Challenge%200.**%20You%20edit%20a%20file%20after%20staging%20it%2C%20then%20commit.%20Does%20the%20commit%20contain%20the%20latest%20edit%20or%20the%20staged%20snapshot%3F%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Python%20setup%0A%0A%20%20%20%20Only%20Marimo%20is%20required%20to%20read%20this%20guide.%20To%20practice%2C%20install%20%5BGit%5D(https%3A%2F%2Fgit-scm.com%2Fdownloads)%20and%20use%20a%20disposable%20practice%20repository%20in%20a%20terminal.%20The%20commands%20below%20are%20displayed%20as%20text%3B%20this%20notebook%20does%20not%20execute%20Git%20commands%20or%20publish%20anything.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20import%20marimo%20as%20mo%0A%0A%20%20%20%20return%20(mo%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Repository%2C%20working%20tree%2C%20and%20staging%20area%0A%0A%20%20%20%20A%20**repository**%20stores%20commits%20and%20their%20history.%20Your%20**working%20tree**%20contains%20the%20files%20you%20edit.%20The%20**index**%2C%20or%20staging%20area%2C%20holds%20the%20snapshot%20selected%20for%20the%20next%20commit.%20A%20**branch**%20is%20a%20movable%20reference%20to%20a%20line%20of%20history%3B%20a%20**clone**%20is%20a%20local%20repository%20copy%3B%20a%20GitHub%20**fork**%20is%20a%20repository%20under%20another%20owner.%20A%20fork%20and%20a%20branch%20are%20different%20things.%0A%0A%20%20%20%20!%5BGit%20local%20operations%5D(https%3A%2F%2Fraw.githubusercontent.com%2FBMClab%2FBMC%2Fmaster%2Fimages%2FGitLocalOperations.png)%0A%0A%20%20%20%20Git%20is%20distributed%3A%20a%20local%20commit%20does%20not%20need%20GitHub%20or%20Internet%20access.%20A%20remote%20copy%20helps%20collaboration%20and%20backup%2C%20but%20Git%20does%20not%20automatically%20capture%20untracked%20data%20or%20unsaved%20edits.%0A%0A%20%20%20%20%60%60%60sh%0A%20%20%20%20git%20status%0A%20%20%20%20git%20diff%0A%20%20%20%20git%20diff%20--cached%0A%20%20%20%20%60%60%60%0A%0A%20%20%20%20%60status%60%20summarizes%20files.%20%60diff%60%20shows%20unstaged%20changes%3B%20%60diff%20--cached%60%20shows%20the%20staged%20changes%20relative%20to%20the%20last%20commit.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20**Exercise%201.**%20You%20stage%20a%20corrected%20equation%2C%20then%20change%20its%20caption.%20What%20does%20the%20next%20ordinary%20%60git%20commit%60%20include%3F%0A%0A%20%20%20%20%2F%2F%2F%20details%20%7C%20Solution%20to%20Exercise%201%0A%20%20%20%20It%20includes%20the%20staged%20equation%20correction.%20The%20later%20caption%20change%20remains%20unstaged%20until%20you%20add%20it%20too.%20Use%20both%20diff%20commands%20to%20see%20the%20two%20snapshots%20separately.%0A%20%20%20%20%2F%2F%2F%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Start%20and%20record%20a%20small%20change%0A%0A%20%20%20%20For%20a%20new%20practice%20folder%20use%20%60git%20init%60.%20To%20obtain%20this%20collection%20instead%2C%20use%20%60git%20clone%20https%3A%2F%2Fgithub.com%2FBMClab%2FBMC.git%60%2C%20then%20%60cd%20BMC%60.%20A%20clone%20already%20has%20a%20repository%3B%20do%20not%20initialize%20another%20inside%20it.%0A%0A%20%20%20%20Set%20your%20author%20identity%20in%20your%20practice%20repository.%20These%20commands%20use%20repository-local%20configuration%3B%20adding%20%60--global%60%20changes%20the%20default%20for%20your%20other%20repositories%20too.%20An%20email%20associated%20with%20your%20GitHub%20account%2C%20including%20its%20private%20noreply%20address%2C%20can%20link%20commits%20to%20that%20account.%0A%0A%20%20%20%20%60%60%60sh%0A%20%20%20%20git%20config%20user.name%20%22Your%20Name%22%0A%20%20%20%20git%20config%20user.email%20%22your-address%40example.com%22%0A%20%20%20%20git%20add%20notebook.py%0A%20%20%20%20git%20diff%20--cached%0A%20%20%20%20git%20commit%20-m%20%22Correct%20units%20in%20the%20walking%20example%22%0A%20%20%20%20git%20log%20--oneline%0A%20%20%20%20%60%60%60%0A%0A%20%20%20%20Run%20the%20notebook%20before%20recording%20the%20change.%20Stage%20explicit%20paths%20so%20temporary%20outputs%20or%20unrelated%20edits%20do%20not%20enter%20the%20commit.%20A%20%60.gitignore%60%20rule%20excludes%20matching%20untracked%20artifacts%3B%20it%20does%20not%20stop%20tracking%20a%20file%20already%20in%20history.%20%60git%20rm%20filename%60%20removes%20and%20stages%20a%20tracked%20file%3B%20deleting%20it%20manually%20and%20then%20staging%20the%20deletion%20is%20also%20valid.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20**Exercise%202.**%20A%20generated%20HTML%20export%20and%20a%20source%20notebook%20both%20changed.%20How%20would%20you%20record%20only%20the%20source%20correction%3F%0A%0A%20%20%20%20%2F%2F%2F%20details%20%7C%20Solution%20to%20Exercise%202%0A%20%20%20%20Inspect%20%60git%20status%60%2C%20run%20%60git%20add%20notebook.py%60%2C%20review%20%60git%20diff%20--cached%60%2C%20and%20commit.%20Leave%20the%20generated%20export%20unstaged.%20The%20source%20and%20reproducible%20environment%20normally%20explain%20the%20result%20better%20than%20a%20pile%20of%20temporary%20exports.%0A%20%20%20%20%2F%2F%2F%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Synchronize%20deliberately%0A%0A%20%20%20%20A%20remote%20is%20a%20named%20repository%20URL.%20%60origin%60%20is%20the%20usual%20name%20created%20by%20cloning.%20Inspect%20it%20before%20sending%20changes%3A%0A%0A%20%20%20%20%60%60%60sh%0A%20%20%20%20git%20remote%20-v%0A%20%20%20%20git%20branch%20--show-current%0A%20%20%20%20git%20fetch%20origin%0A%20%20%20%20git%20pull%20--ff-only%0A%20%20%20%20%60%60%60%0A%0A%20%20%20%20%60fetch%60%20downloads%20history%20without%20integrating%20it%20into%20your%20working%20branch.%20%60pull%20--ff-only%60%20fetches%20and%20advances%20that%20branch%20only%20when%20no%20merge%20is%20needed.%20If%20histories%20diverge%2C%20inspect%20the%20changes%20and%20choose%20a%20merge%20or%20other%20agreed%20workflow%3B%20repeating%20the%20command%20will%20not%20resolve%20a%20conflict.%20A%20merge%20combines%20histories%2C%20and%20conflicting%20edits%20need%20a%20human%20decision%20followed%20by%20a%20notebook%20run.%0A%0A%20%20%20%20When%20you%20intend%20to%20publish%20and%20have%20write%20access%2C%20%60git%20push%20origin%20YOUR_BRANCH%60%20sends%20local%20commits%20to%20that%20branch.%20Replace%20%60YOUR_BRANCH%60%20with%20the%20actual%20branch%20name%3B%20this%20repository%20uses%20%60master%60%2C%20while%20other%20projects%20may%20use%20%60main%60%20or%20another%20name.%20GitHub%20HTTPS%20authentication%20uses%20a%20credential%20manager%20or%20token%2C%20not%20your%20account%20password%3B%20SSH%20uses%20a%20registered%20key.%20See%20%5BGitHub%20authentication%5D(https%3A%2F%2Fdocs.github.com%2Fen%2Fauthentication%2Fkeeping-your-account-and-data-secure%2Fabout-authentication-to-github).%0A%0A%20%20%20%20If%20you%20fork%20a%20project%2C%20your%20fork%20is%20usually%20%60origin%60.%20You%20can%20name%20the%20original%20repository%20%60upstream%60%2C%20fetch%20it%2C%20and%20integrate%20its%20changes%20intentionally.%20Cloning%20a%20public%20repository%20does%20not%20give%20you%20permission%20to%20push%20to%20it.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20**Exercise%203.**%20Your%20local%20notebook%20is%20committed%20while%20the%20network%20is%20unavailable.%20What%20is%20saved%2C%20and%20what%20remains%20to%20happen%20before%20a%20collaborator%20can%20fetch%20it%3F%0A%0A%20%20%20%20%2F%2F%2F%20details%20%7C%20Solution%20to%20Exercise%203%0A%20%20%20%20The%20commit%20is%20saved%20in%20your%20local%20repository.%20It%20must%20be%20pushed%20to%20a%20remote%20that%20your%20collaborator%20can%20access.%20GitHub%20is%20not%20involved%20in%20making%20the%20local%20commit.%0A%20%20%20%20%2F%2F%2F%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Recover%20and%20review%0A%0A%20%20%20%20%60git%20log%20--oneline%60%20finds%20commits%3B%20%60git%20show%20COMMIT%60%20inspects%20one.%20%60git%20restore%20--staged%20notebook.py%60%20removes%20a%20change%20from%20the%20staging%20area%20while%20keeping%20the%20working%20file.%20%60git%20restore%20notebook.py%60%20instead%20discards%20unstaged%20changes%20in%20that%20file%2C%20so%20inspect%20the%20diff%20first.%0A%0A%20%20%20%20%60git%20revert%20COMMIT%60%20records%20a%20new%20commit%20that%20reverses%20the%20changes%20of%20the%20named%20commit.%20It%20does%20**not**%20cancel%20every%20later%20commit.%20This%20is%20useful%20when%20a%20published%20correction%20itself%20needs%20correcting.%20For%20experimental%20work%2C%20%60git%20switch%20-c%20experiment%60%20starts%20a%20new%20branch%3B%20branch%20workflows%20are%20optional%20for%20the%20small%20exercises%20here.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20**Exercise%204.**%20You%20want%20to%20unstage%20a%20notebook%20but%20keep%20your%20edits.%20Which%20restore%20command%20fits%2C%20and%20which%20would%20risk%20discarding%20them%3F%0A%0A%20%20%20%20%2F%2F%2F%20details%20%7C%20Solution%20to%20Exercise%204%0A%20%20%20%20Use%20%60git%20restore%20--staged%20notebook.py%60.%20Without%20%60--staged%60%2C%20%60git%20restore%20notebook.py%60%20restores%20the%20working%20file%20from%20the%20index%20and%20discards%20its%20unstaged%20edits.%20The%20destination%20matters.%0A%20%20%20%20%2F%2F%2F%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Checkpoint%20questions%0A%0A%20%20%20%201.%20Is%20a%20commit%20automatically%20a%20push%3F%0A%20%20%20%202.%20What%20snapshot%20does%20%60git%20diff%20--cached%60%20inspect%3F%0A%20%20%20%203.%20Is%20a%20fork%20the%20same%20as%20a%20branch%3F%0A%0A%20%20%20%20%2F%2F%2F%20details%20%7C%20Checkpoint%20answers%0A%20%20%20%201.%20No.%0A%20%20%20%202.%20The%20index%20relative%20to%20the%20last%20commit.%0A%20%20%20%203.%20No%3B%20a%20fork%20is%20another%20repository.%0A%20%20%20%20%2F%2F%2F%0A%0A%20%20%20%20%23%23%20Problems%0A%0A%20%20%20%201.%20Name%20the%20command%20to%20inspect%20unstaged%20changes.%0A%20%20%20%202.%20Name%20the%20command%20to%20unstage%20%60guide.py%60%20while%20preserving%20its%20working%20copy.%0A%20%20%20%203.%20Does%20%60git%20revert%20ABC123%60%20undo%20every%20commit%20after%20ABC123%3F%0A%20%20%20%204.%20What%20happens%20when%20%60git%20pull%20--ff-only%60%20encounters%20diverging%20histories%3F%0A%0A%20%20%20%20%2F%2F%2F%20details%20%7C%20Final%20answers%0A%20%20%20%201.%20%60git%20diff%60.%0A%20%20%20%202.%20%60git%20restore%20--staged%20guide.py%60.%0A%20%20%20%203.%20No%3B%20it%20reverses%20the%20changes%20introduced%20by%20ABC123%20in%20a%20new%20commit.%0A%20%20%20%204.%20It%20refuses%20the%20integration%3B%20the%20histories%20need%20an%20explicit%20decision.%0A%20%20%20%20%2F%2F%2F%0A%0A%20%20%20%20%23%23%20Go%20deeper%0A%0A%20%20%20%20%5BPro%20Git%5D(https%3A%2F%2Fgit-scm.com%2Fbook%2Fen%2Fv2)%20%E2%80%94%20work%20through%20recording%20changes%2C%20remotes%2C%20and%20undoing%20changes%20when%20you%20need%20more%20detail.%0A%0A%20%20%20%20%23%23%23%20Video%20lectures%20on%20the%20Internet%0A%0A%20%20%20%20%5BMIT%20Missing%20Semester%3A%20Version%20Control%5D(https%3A%2F%2Fmissing.csail.mit.edu%2F2020%2Fversion-control%2F)%20%E2%80%94%20an%20embedded%20lecture%20on%20the%20history%20graph%20and%20the%20meaning%20of%20everyday%20commands.%0A%0A%20%20%20%20%23%23%20References%0A%0A%20%20%20%20-%20Scott%20Chacon%20and%20Ben%20Straub%2C%20%5BPro%20Git%5D(https%3A%2F%2Fgit-scm.com%2Fbook%2Fen%2Fv2).%20%5BGit%20reference%5D(https%3A%2F%2Fgit-scm.com%2Fdocs).%20%5BGitHub%20authentication%5D(https%3A%2F%2Fdocs.github.com%2Fen%2Fauthentication%2Fkeeping-your-account-and-data-secure%2Fabout-authentication-to-github).%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0Aif%20__name__%20%3D%3D%20%22__main__%22%3A%0A%20%20%20%20app.run()%0A
c690a6b9687dc9c4935e93950e43d405