2022-10-25
A lab notebook for computational analyses and code development.
git
git
(i.e. have you ever worked on the same document as someone else?)
Version control systems manage this process
The complete history of commits and metadata is a repository
CVS, Subversion, RCS: legacy systems
git
, Mercurial: modern distributed VC tools
git
git
for first use on a computergit config --global
git
needs to know who you are for metadatagit
wants your preferences for display/editingLive Presentation
git config --global user.name "Vlad Dracul" git config --global user.email "vlad@tran.sylvan.ia" git config --global color.ui "auto" git config --global core.editor "nano -w" git config --global core.editor \ "'C:\Program Files (x86)\Notepad++\notepad++.exe' \ -multiInst -notabbar -nosession -noPlugin"
git
repositorygit
repositoryLive Presentation
git init git status
git
workflowLive Presentation
nano mars.txt
git
commitgit
that it should track a file (watch for changes): git add
git commit
the file (keep a copy of the file in the repository, in its current state)Live Presentation
git add mars.txt git commit -m "start notes on Mars as a base" git log
git add
)Live Presentation
nano mars.txt git diff git add mars.txt git diff git commit
myfile.txt
to the local git
repository?1. git commit -m "add recent changes" 2. git init myfile.txt; git commit -m "add recent changes" 3. git add myfile.txt; git commit -m "add recent changes" 4. git commit -m myfile.txt "add recent changes"
mars.txt
.earth.txt
with one-line comment on Earth.commit
)HEAD
of a repository isgit
commit numbersHEAD
HEAD~1
HEAD~2
git diff
git diff
to see what changed for a file at each commitLive Presentation
git diff HEAD~1 mars.txt git diff HEAD~2 mars.txt
Live Presentation
git diff d22195b9ec3c8fb4c2ce0f52f344b95ce5d0d0e3 mars.txt git diff d221 mars.txt
Live Presentation
git checkout HEAD mars.txt
git checkout
git checkout
“checks out” files from the repo
data_cruncher.py
(but no other files)?1. $ git checkout HEAD 2. $ git checkout HEAD data_cruncher.py 3. $ git checkout HEAD~1 data_cruncher.py 4. $ git checkout <unique ID of last commit> data_cruncher.py
git
to ignore files and directoriesLive Presentation
mkdir results touch a.dat results/a.out
.gitignore
is a special file in your repository root
git
to ignore specified files/directoriesLive Presentation
nano .gitignore git status --ignored git add -f b.dat
mkdir planets cd planets git init
Live Presentation
origin
is a local nickname for the remote repo (a common choice)Live Presentation
git remote add origin https://github.com/widdowquinn/planets.git git push origin master
Live Presentation
git pull origin master
Live Presentation
cd /tmp/ git clone https://github.com/<collaborator>/planets.git git remote -v
as the collaborator
pluto.txt
- (content your own)Live Presentation
cd planets nano pluto.txt git add pluto.txt git commit -m "Notes on Pluto" git push origin master
as the owner
git remote -v
git pull
the changes made by your collaboratorLive Presentation
cd ~/planets/ git pull origin master
git
conflictsgit pull
before working; git push
when donegit push
when done…in your pairs
mars.txt
then
mars.txt
Live Presentation
cd ~/planets nano mars.txt git push origin master cd /tmp/planets nano mars.txt git push origin master
To https://github.com/<collaborator>/planets.git ! [rejected] master -> master (fetch first) error: failed to push some refs to 'https://github.com/<collaborator>/planets.git' hint: Updates were rejected because the remote contains work that you do hint: not have locally. This is usually caused by another repository pushing hint: to the same ref. You may want to first integrate the remote changes hint: (e.g., 'git pull ...') before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details.
git
detects overlapping changes
git
defers to humans for how to resolve: communicate!Live Presentation