- Install git if not already installed instructions here
- get github account as well
** Why should we be using version control?**
- To keep track of changes (avoid the
mypaper_final_final_final_reallythistime.docx
problem.) - To give reasons for each change.
- To preserve multiple versions of documents simultaneously. (this can be done with "branches").
- To collaborate with others and not create conflicting versions of the same document.
- Introduction to Git
- Git in the command line
- First steps
- Setting up repositories
- Tracking Changes
- History
.gitignore
- Using Github (and other remotes)
- Collaborating
- Conflicts
- Git in RStudio
- Git keeps track of your changes. It monitors changes as if they were separate from the document itself.
Git commands take the format git verb options
You will need to tell git who you are so it knows who made the changes in your documents.
git config --global user.name "Mickey Mouse"
git config --global user.email "mickey1234@gmail.com"
Optional: Change core editor to nano
from vim
(for more editor options see https://swcarpentry.github.io/git-novice/02-setup/index.html)
git config --global core.editor "nano -w"
Note: You can check out your settings with the following command
git config --list
repository: a storage area (usually a directory) where git can store all the history of a project and information of who changed what and when.
- Make a new repository
mkdir microbes
cd microbes
git init
Check the repository was created
git status
ls -a
You'll see a message about the branch, the commits, and a list of the files including the .git
file.
First we'll need some files...
nano cheese.txt
Type the following text in cheese.txt
and then press ctrl+o
ctrl+x
to save changes and exit nano
.
Cheese is made with milk.
- Make changes to file(s)
- "stage" (
git add
) those file(s). - commit the changes (
git commit -m "message about changes"
)
Now let's do this ourselves:
Check on git status
git status
git add cheese.txt
git commit cheese.txt -m "wrote about cheese ingredients"
Notes about commit messages:
- like a lab notebook - should be informative
- ideally, commit often and in small parts. This makes reverting back easier.
git status
Let's add some more changes...
nano cheese.txt
Type the following text in cheese.txt
and then press ctrl+o
ctrl+x
to save changes and exit nano
.
Cheese is made with milk and microbes.
Cheese is good.
Check on the status
git status
(cheese.txt has been modified, but not staged)
What if we forgot exactly what changed?
git diff
git diff --color-words # shows word-by-word changes
Shows line-by-line changes in our modified documents. Now that we know the changes, and like them, we can add and commit them.
git add cheese.txt
git commit cheese.txt -m "added microbes to ingredients list"
- Create a new file called
nutritional_yeast.txt
- Write the following line for
nutritional_yeast.txt
Nutritional yeast is made with microbes.
add
andcommit
the file.
- RSTUDIO
- Github is not the same as
git
. git
can be used without a github account.- Github accounts allow other people to use the internet to connect with a
git
repository that is hosted there.