PhD Comics
Simple formal system for tracking all changes to a project
Learning curve is steep, but when you need it you REALLY need it
Your closest collaborator is you six months ago, but you don't reply to emails.
– Paul Wilson, UW-Madison
We want to let git
know who we are so there are some simple configuration options we should setup.
Let's first tell git
who we are, and what editor we want to use.
$ git config --global user.name "Colin Rundel" $ git config --global user.email "rundel@gmail.com" $ git config --global push.default simple $ git config --global core.editor nano $ git config --global credential.helper 'cache --timeout=600000'
We also want to do this on every machine we will be using - local
, saxon
, OIT VM
, etc.
Make sure to put this information in your github profile as well.
For the time being
cr173@saxon [Sta523]$ git clone https://github.com/Sta523-Fa17/DavidRobinson_TrumpTweets.git Cloning into 'DavidRobinson_TrumpTweets'... remote: Counting objects: 3715, done. remote: Total 3715 (delta 0), reused 0 (delta 0), pack-reused 3715 Receiving objects: 100% (3715/3715), 199.51 MiB | 26.92 MiB/s, done. Resolving deltas: 100% (2049/2049), done.
cr173@saxon [Sta523]$ ls DavidRobinson_TrumpTweets cr173@saxon [Sta523]$ ls -a DavidRobinson_TrumpTweets/ 2016-08-09-trump-tweets.Rmd DavidRobinson_TrumpTweets.Rproj trump_tweets.rda trump_tweets_df.rda 2016-08-09-trump-tweets.html README.md trump_tweets_20161128.csv
cr173@saxon [Sta523]$ cd hDavidRobinson_TrumpTweets cr173@saxon [DavidRobinson_TrumpTweets]$ git status On branch master Your branch is up-to-date with 'origin/master'. nothing to commit, working directory clean
Lets create a README.md
file to include team member names and email addresses.
cr173@saxon [DavidRobinson_TrumpTweets]$ nano README.md cr173@saxon [DavidRobinson_TrumpTweets]$ cat README.md # DavidRobinson_TrumpTweets's Repo ## Team Members * Colin Rundel - rundel@gmail.com
cr173@saxon [DavidRobinson_TrumpTweets]$ git status On branch master Your branch is up-to-date with 'origin/master'. Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git checkout -- <file>..." to discard changes in working directory) modified: README.md no changes added to commit (use "git add" and/or "git commit -a")
cr173@saxon [DavidRobinson_TrumpTweets]$ echo -e "* Add other team member's info\n* Fix formatting\n" > TODO cr173@saxon [DavidRobinson_TrumpTweets]$ cat TODO * Add other team member's info * Fix formatting
cr173@saxon [DavidRobinson_TrumpTweets]$ git status On branch master Your branch is up-to-date with 'origin/master'. Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git checkout -- <file>..." to discard changes in working directory) modified: README.md Untracked files: (use "git add <file>..." to include in what will be committed) TODO no changes added to commit (use "git add" and/or "git commit -a")
One file README.md
is tracked and modified (repo is already has this file but our current version differs from the previously saved version)
The other file TODO
is untracked (this file does not exist in the repo)
Our next step is the same for both files - we want to stage our changes using git add
.
cr173@saxon [DavidRobinson_TrumpTweets]$ git add README.md cr173@saxon [DavidRobinson_TrumpTweets]$ git add TODO
cr173@saxon [DavidRobinson_TrumpTweets]$ git status On branch master Your branch is up-to-date with 'origin/master'. Changes to be committed: (use "git reset HEAD <file>..." to unstage) modified: README.md new file: TODO
By using git add
we have made git aware of the current version of both files, but we have not actually saved the changes yet.
To save the changes (locally) we need to commit them using git commit
, since this change will be saved it is customary to add a message about the nature of the changes being made (for future reference).
cr173@saxon [DavidRobinson_TrumpTweets]$ git commit -m "Added Colin's information to README; Added TODO file." [master f9c548c] Added Colin's information to README; Added TODO file. 2 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 TODO
cr173@saxon [DavidRobinson_TrumpTweets]$ git status On branch master Your branch is ahead of 'origin/master' by 1 commit. (use "git push" to publish your local commits) nothing to commit, working directory clean
We've saved our changes but we're now out of sync with the repository on github.
What if at the same time I was making these edits my teammate John Doe was making changes to README.md
on github?
github README edit
github README commit
github README status
We can attempt to send our changes back to github by using git push
cr173@saxon [DavidRobinson_TrumpTweets]$ git push To git@github.com:Sta523-Sp17/DavidRobinson_TrumpTweets.git ! [rejected] master -> master (fetch first) error: failed to push some refs to 'git@github.com:Sta523-Sp17/DavidRobinson_TrumpTweets.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.
cr173@saxon [DavidRobinson_TrumpTweets]$ git pull remote: Counting objects: 3, done. remote: Compressing objects: 100% (3/3), done. remote: Total 3 (delta 0), reused 0 (delta 0) Unpacking objects: 100% (3/3), done. From github.com:Sta523-Sp17/DavidRobinson_TrumpTweets 6b79df7..804e091 master -> origin/master Auto-merging README.md CONFLICT (content): Merge conflict in README.md Automatic merge failed; fix conflicts and then commit the result.
cr173@saxon [DavidRobinson_TrumpTweets]$ git status On branch master Your branch and 'origin/master' have diverged, and have 1 and 1 different commit each, respectively. (use "git pull" to merge the remote branch into yours) You have unmerged paths. (fix conflicts and run "git commit") Unmerged paths: (use "git add <file>..." to mark resolution) both modified: README.md no changes added to commit (use "git add" and/or "git commit -a")
cr173@saxon [DavidRobinson_TrumpTweets]$ cat README.md DavidRobinson_TrumpTweets Repo ======= ## Team Members <<<<<<< HEAD * Colin Rundel - rundel@gmail.com ======= * John Doe - j.doe@gmail.com >>>>>>> 804e09178910383c128035ce67a58c9c1df3f558
<<<<<<<
- Indicates the start of the merge conflict.=======
- Indicates the break point used for comparison.>>>>>>>
- Indicates the end of the lines that had a merge conflict.Edit the merged file to reflect the changes you actually want.
cr173@saxon [DavidRobinson_TrumpTweets]$ nano README.md cr173@saxon [DavidRobinson_TrumpTweets]$ cat README.md DavidRobinson_TrumpTweets Repo ======= ## Team Members * Colin Rundel - rundel@gmail.com * John Doe - j.doe@gmail.com
cr173@saxon [DavidRobinson_TrumpTweets]$ git add README.md retBook-2:DavidRobinson_TrumpTweets rundel$ git status On branch master Your branch and 'origin/master' have diverged, and have 1 and 1 different commit each, respectively. (use "git pull" to merge the remote branch into yours) All conflicts fixed but you are still merging. (use "git commit" to conclude merge) Changes to be committed: modified: README.md $ git commit -m "Fix Merge conflict"
cr173@saxon [DavidRobinson_TrumpTweets]$ git status On branch master Your branch is ahead of 'origin/master' by 2 commits. (use "git push" to publish your local commits) nothing to commit, working directory clean cr173@saxon [DavidRobinson_TrumpTweets]$ git push Counting objects: 7, done. Delta compression using up to 4 threads. Compressing objects: 100% (6/6), done. Writing objects: 100% (7/7), 791 bytes | 0 bytes/s, done. Total 7 (delta 1), reused 0 (delta 0) To git@github.com:Sta523-Sp17/DavidRobinson_TrumpTweets.git 804e091..9c4a5e7 master -> master
cr173@saxon [DavidRobinson_TrumpTweets]$ git log commit 9c4a5e78866e00fccb78ddf170b62bc74812a7c7 Merge: f9c548c 804e091 Author: Colin Rundel <rundel@gmail.com> Date: Sun Jan 15 21:19:11 2017 -0400 Merge changes commit 804e09178910383c128035ce67a58c9c1df3f558 Author: Colin Rundel <rundel@gmail.com> Date: Sun Jan 15 17:43:47 2017 -0400 Added John Doe to README commit f9c548c0db0ee9b547a73ab44bacbba2a7facf04 Author: Colin Rundel <rundel@gmail.com> Date: Sun Jan 15 17:36:37 2017 -0400 Added Colin's information to README; Added TODO file. commit 6b79df75ce42e43ead368b0bb7e52246cf5ecc10 Author: Colin Rundel <rundel@gmail.com> Date: Sun Jan 15 16:18:27 2017 -0400 Initial commit
Above materials are derived in part from the following sources: