By the end of class, you should be able to
edit files
staging area
git add
git commit
starter repo
your copy
git clone
your machine
fork
git push
"First"
git commit -m "First"
"Second"
"Third"
"Fourth"
git commit -m "Second"
git commit -m "Third"
git commit -m "Fourth"
Git history has been a linear sequence of commits.
HEAD
Branches allow for non-linear commits.
main
main
main
main
experiment
bugfix
experiment
experiment
git branch
git branch [my_branch]
git checkout [my_branch]
git checkout -b [my_branch]
git branch -d [my_branch]
Open the README.md file (in Atom)
Create and
checkout
a new branch called
experiment
Add another item to the end of the list
Add and commit your change
checkout
the
main branch
Add yet another item to the beginning of the list
Commit your change
Switch between the experiment and main branches (clicking on Atom in between). See the file contents changing?
main
main
experiment
experiment
HEAD
HEAD
HEAD
HEAD
git branch experiment
git checkout experiment
git commit
git commit
git checkout main
git commit
git checkout experiment
HEAD
HEAD
experiment
HEAD
We can
merge
two branches back together, producing a commit that contains the combined changes from both branches
main
main
experiment
HEAD
HEAD
git merge [other_branch]
Make sure you are on the
main branch
(use
git branch
to check; the current branch has a
*
)
Use
git merge
to merge the
experiment branch into
main branch.
If you get dropped into
vi, hit
:wq
(colon then w then q) to accept the message.
Check in Atom that the file now contains both sets of changes!
You should be on the main branch.
Create and checkout
a new branch called danger
On the danger branch, change the word "kittens" to "puppies". Remember to commit
your change.
checkout
the main branch again.
Change the word "kittens" to something else that is pleasant. commit
your change.
Use git merge
to merge the danger branch into main branch
DON'T PANIC
A merge conflict is when two commits from different branches include different changes to the same code.
Git does not know which version to keep, so makes you choose.
Merge conflicts must be resolved manually
In order to
resolve a conflict, you need to edit the file (code) so that you pick which version to keep.
git will add "code" where you need to make a decision:
In order to
resolve a conflict, you need to edit the file (code) so that you pick which version to keep.
git will add "code" where you need to make a decision:
<<<<<<< HEAD
# This is the code from the "local" version (the branch you merged INTO)
# a.k.a the version from the HEAD commit
message <- "I am an original"
lyric <- "I've got no strings to hold me down"
# There can be multiple lines that conflict, including lines being deleted
=======
# This is the code from the "remote" version (the branch you merged FROM)
message <- "I think I'm a clone now..."
# The lines need not be related in content, they've just changed in a way
# that git can't figure out which to keep!
>>>>>>> f292a3332aedc8df3e8e8cf22ca3debc214c6460
the two versions to pick from
a divider between the versions
end conflict area
git add .
git commit -m "Merge branch 'other'"
git status
to see which files have merge conflicts. Note that files may have more than one!
<<<<<<<
and
=======
and
>>>>>>>
!!
add
and
commit
your changes (the code you "modified" to resolve the conflict):
Because GitHub just hosts normal repositories, GitHub has branches as well! These can (but need not) correspond with the branches on your local machine.
git branch -a
git pull [remote] [branch]
git fetch
then
git merge
git fetch
Can cause conflicts!
git push [remote] [branch]
git push [remote] --all
Multiple people's local repositories can be linked to the same remote repository, allowing them to push and pull to the same central location.
Partner up with a partner ("Howdy pardn'r")
One person should add the other as a collaborator
The added person will then need to clone their partner's repo on their machine
Remember to do this in a different folder!
Partner: edit the README.md file so it includes a message to your partner (be nice)
add and commit your change as usual.
Me: create a new script partner.R that prints a message to your partner (be nice)
add and commit as usual.
Partner: push their changes to Github
Then Me: push their changes to Github
Me: pull to merge in Person 1's message
Both people should confirm the changes are local!
Partner: push your changes to Github
Me: pull in Person 2's message and merger
You both should now have up-to-date code!
Me: edit the partner.R file so that it prints a different message. Change the existing line of code.
add and commit your change as usual.
Partner: edit the partner.R file so that it prints a different message. Change the existing line of code.
add and commit as usual.
Partner: push their changes to Github
What happened?
Then Me: push their changes to Github.
But they need to pull first...
git add .
git commit -m "Merge branch 'other'"
git status
to see which files have merge conflicts. Note that files may have more than one!
<<<<<<<
and
=======
and
>>>>>>>
!!
add
and
commit
your changes (the code you "modified" to resolve the conflict):
A GitHub service that
hosts web pages (
.html
files) found in a repository's
gh-pages
branch.
# Make sure you are on the `master` branch
git branch
# Checkout a new gh-pages branch from here. This branch will
# have the same commits as `main` to this point
git checkout -b gh-pages
# Upload web site to GitHub
git push -u origin gh-pages
Visit published page at:
Make sure you are on the main branch
index.html
file is in the _root_ of the repository, and you have committed all of your changes.
checkout
a new
gh-pages branch
push
the
gh-pages branch to GitHub. View the web page at
https://USERNAME.github.io/git_branch_practice
switch back to the main branch
Change the
index.Rmd
file in some way, then re-knit. Commit your changes.
switch
back to
gh-pages and
merge
from
main
push
the new changes to GitHub
A2: COVID due Monday
Read: Programming Skills Ch 15-16 (required)
Be comfortable with Ch 1-12 + 18, 20
Read: Data Feminism: Chapter 4
Next: data visualization w/ ggplot