Norfolk Data Science: http://www.meetup.com/NorfolkDataSci/
author: Josiah Baker & Steve Mortimer date: November 1, 2016 css: presentation-css.css
title: false
-
Instructions for installing on all platforms (Linux, Mac, Windows) are available here:
https://git-scm.com/book/en/v2/Getting-Started-Installing-Git - You can verify that your installation worked by checking the version of Git from the command line.
- Mac Users: Open up your terminal
- Windows Users: Open up Git Bash
- Run the following command:
git --version
title: false
-
Check for existing keys
ls -al ~/.ssh -
If you don't have keys, then generate a key
ssh-keygen -t rsa -b 4096 -C "[email protected]" -
Start the key agent
eval "$(ssh-agent -s)" -
Add the key to the agent
ssh-add ~/.ssh/id_rsa
title: false
- Log into GitHub -> Settings -> SSH and GPG keys
- Copy the key to clipboard and Paste
- Mac Users
pbcopy < ~/.ssh/id_rsa.pub - Windows Users
cat ~/.ssh/id_rsa.pub > /dev/clipboard
- Mac Users
title: none
-
Repositories are a folder
Create a folder with same name as new repomkdir ~/members
cd members -
Copy/Paste the GitHub commands
echo "# test" >> README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin [email protected]:{UserName}/members.git
git push -u origin master
title: none
-
The first command initializes the repository
git init -
The second command tells git to track an individual file
git add README.md -
This commits changes on a tracked file
git commit -m "first commit" -
Now we tell git where our remote repository is
git remote add {name} [email protected]:{UserName}/members.git -
Save your local commited changes to the remote repository
git push -u {name} {branch name}
title: none
- Add your Name to the README file as a bullet
- Save your changes
-
"Stage" all files, commit, then push to GitHub
git add .
git commit -m "Update README" -m "Add Change"
git push origin master
Guidelines on how to make good commit messages:
http://chris.beams.io/posts/git-commit/
title: none
-
Navigate to where you want repo to be
mkdir ~/my-repos
cd ~/my-repos -
Copy/Paste the GitHub commands
git clone [email protected]:NorfolkDataSci/members.git
- Check that a folder with same name as the repo was created in the current working directory
title: none
- When 2 people change the same lines of code it creates a "merge conflict"
- Merge conflicts need to be "resolved", meaning reconcile the differences between commits
- The first sign is not being able to push your recent commits
title: none
-
So you follow the hint and pull
git pull
-
Then you receive a message about a "CONFLICT"
(fix conflicts, then commit)
title: none
- Open up the conflicted file (in this case README.md)
- You will notice weird markings
- The marker showing the start of the conflict
"<<<<<<< HEAD"
- The marker showing the end of your change (HEAD)
"======="
- The marker showing the end of the server's version
">>>>>>> 7bd926b......"
- The marker showing the start of the conflict
title: none
- Open up the conflicted file (in this case README.md)
- Edit file to how you want it. Make sure to remove weird markings
- Commit like any other change and you're done (Resolved!)
git add .
git commit -m "Fix merge conflict"
git push
title: none
- It's possible to erase commits back to a certain point
- Click copy button to get commit hash on clipboard
-
Run the following command to reset your local commit history
git reset ––hard 2feeb51899f80a2ddea5b353260841350285406f
-
Commit like any other change, but add "-f" on your git push
git push -f
title: none
-
Start work on a "branch". It's a copy of your current state
git checkout -b my_branch
-
This branch is only local, so push it to GitHub
git push -u origin my_branch
- Make a change to the README.md file, commit, & push
- Next switch back to master branch and look at README.md
- Your change is gone! It only exists on "my_branch". Switch back now
git checkout master
git checkout my_branch
title: none
-
Branches isolate code until ready to be "merged"
Create a pull request when you are ready to merge- Look in GitHub for "my_branch"
- Click the button that says "Compare & pull request"
- Pick a "target" branch (where you want new code to be applied)
- Review that your changes make sense
- Add a message outlining why this pull request is needed and how it essentially solves the problem of why it was needed
- Stashing work with git stash and git stash pop
- More advanced branching with git checkout
- Forking and staying current with git rebase
- Closing issues via commit messages (more info here)
- Other ways to fix or undo your git history (more info here)
- Git LFS (Large File Store) for versioning large data files