Use slides
Slide: Setting Up Git
git config
to configure a user name, email address, editor, and other preferences once per machine.”git help
or git help <command>
if you get stuck!”cats-as-data
directory
$ cd ~/Desktop/cats-as-data # or wherever you unzipped it
git init
to initialize our git repository
$ git init
.git
directory. Git stores all information about our project in here.
If we ever delete it, we will lose our project history
$ ls -a # or dir /ah on windows
New Command: git status
to check current state of the repository
git status
highlights:
git add
to tell Git to track files
$ git add README.md
git status
again
$ git status
git status
highlights:
new file
Changes to be committed
is because we haven’t recorded this as a commit yet$ git add cats-human-situations.csv
git commit
to commit the changes to our repository
$ git commit -m "add notes on metadata, and the metadata"
git commit
highlights:
git add
command in a commit-m
flag stands for message. used to record short description of the changes-m
flag is not specified, our chosen editor will pop up and we’ll be asked to add the commit message there.Describe good commit messages
git log
to view our project history
$ git log
git log
highlights:
ls
and notice that there is just one copy of README.md
This is because Git saves all history in .git
folder. So your working directory stays clean and up to date
README.md
with your editor
The images are in the `images/` subdirectory of this repository.
Run git status
- Notice we see it see the file it knows about is modified
no changes added to commit.
- We haven’t done a git add
for the file yet
Always good practice to review changes before saving them
New Command git diff
to compare our changes with the most recent commit
$ git diff
git diff
highlights:
diff
command comparing the old and new versions of the
file.acbad52
and 17e3cdd
are unique identifiers for
those versions.+
marker in the first column shows where we
added a line. If we had instead removed lines, there would be -
markers instead.$ git add README.md
$ git commit -m "readme: where are the files?"
Terminology: Diff vs Patch vs Commit (slide?)
Add images
folder to repository and show diff
$ git add images
$ git diff
git --staged
$ git diff --staged
images
$ git commit -m "add pictures of cats"
git log
Introduce HEAD
(pointer to most recent commit)
Open README.md
and add a new line and save:
If you would like, you can also put images of dogs and hexagonal software logos here.
~
syntax for showing older commits
$ git diff HEAD~1 README.md
$ git diff HEAD~2 README.md
$ git diff HEAD~2
git show
to see changes made in an older commit with all information (by who, when, etc.)
$ git show HEAD~2 README.md
$ git log #(find oldest commit hash and take first 5)
$ git diff <first 5 characters> README.md
Now we’re going to talk about restoring an older version. Open editor and replace the contents of README.md
with
anything. Junk text.
git status
(notice it tells us how to revert)git checkout
to bring back previous version of README.md
$ git checkout HEAD README.md
git diff
displays differences between commits.git checkout
recovers old versions of files.cats-as-data
. Highlight Git sees the file
now.
$ git status
We want to ignore cats-human-situations.md
because it’s a derivative
Let’s open .gitignore
and add the filename
cats-human-situations.md
git status
again. Notice Git no longer lists the file.
$ git status
.gitignore
file, so others have the same experience/behavior.
$ git add .gitignore
$ git commit -m "Add the ignore file"
$ git status
.gitignore
file tells Git what files to ignoreSlide: Working with Branches
git branch
to look at current branches. Asterisk by branch name tells you what branch you’re on.
$ git branch
$ git branch title-caps
$ git branch
Still on the master
branch. You can also check this with git status
If you need to rename a branch, you can use the -m
move flag.
$ git branch -m title-cads title-caps
git checkout
$ git checkout title-caps
-b
flag
$ git checkout -b title-caps
$ git add cats-human-situations.md
$ git commit -m "fix all caps in titles"
--oneline
flag
$ git log --oneline
master
and look at the log. New commit not on master
$ git checkout master
$ git log --oneline
README.md
file. Open editor and add the following:
~~~
Cleanup plan:$ git add README.md
$ git commit -m "add cleanup plan"
$ git log --graph --oneline --decorate --all
Intro and context (bringing changes back into master
)
Sometimes branches live permanently
Title edits exist in title-caps
, not in master
. Need to merge title-caps
into master
. Checkout master
.
$ git checkout master
git merge
to bring commits into master
.
$ git merge title-caps
If editor window pops up, it’s OK! We need to provide a merge commit message
Look at recent commits on master
$ git log --oneline
title-caps
branch. To verify changes were merged, we can run branch
with --merged
flag from master
$ git checkout master
$ git branch --merged
$ git branch -d title-caps
git branch
to view current branches”git branch branch-name
to create a new branch”git checkout branch-name
to switch to a branch”git branch -m branch-name
to rename a branch”git merge branch-name
to merge a branch”git branch -d delete-me
to delete a branch”Log in to Github
Create repository
Copy https
url of the repo
Add the repository as the origin
remote. origin
is a convention.
$ git remote add origin https://github.com/your-username/cats-as-data.git
$ git remote -v
git push
to push our local repository content to our Github repository. Remote version of commit
$ git push origin master
git pull
to pull changes from our Github repository to our local repository. Pulling now has no
effect.
$ git pull origin master
git push
copies changes from a local repository to a remote repository.”git pull
copies changes from a remote repository to a local repository.”Slide: Collaborating
Pair up. Though this can be done solo as well!
Owner and Collaborator roles.
Owner: give Collaborator access to Github repo (Settings -> Collaborators
Collaborator: New Command: git clone
to get local copy of the owner’s repository to make changes. Replace
ccline
with owner’s username.
$ git clone https://github.com/ccline/cats-as-data.git ~/Desktop/ccline-cats-as-data
Check in! And view diagram of repositories
Collaborator: Open project README.md
file. Choose a part of the cleanup plan to work on.
Collaborator: create branch and make changes
$ git checkout -b standardize-dates
$ git add cats-human-situations.csv
$ git commit -m "Standardize all dates"
Check in!
Let’s push
our changes to the Owner’s repo:
$ git push origin standardize-dates
Collaborator: Create Pull Request (demo)
Check in!
Owner: Review Pull Request and Merge
Owner: get changes locally and view csv
$ git pull origin master
$ git log
git clone
copies a remote repository with a remote called origin
automatically setup.”Introduction/Context
Create new branch to work on:
$ git checkout master
$ git branch update-plan
README.md
(in master
):
~~~$ git add README.md
$ git commit -m "add subject reconciliation to plan"
update-plan
branch
$ git checkout update-plan
README.md
(in update-plan
):
~~~master
and try to merge update-plan
$ git checkout master
$ git merge update-plan
Review Merge image
Open README.md
to review merge conflicts to resolve
Update README.md
to include both changes
Add README.md
, check git status
, and commit
$ git add README.md
$ git status
$ git commit -m "Merge changes from update-plan branch"