Learning Git
Josiah Baker & Steve Mortimer
November 1, 2016
Installing git
-
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
Copy Public Half of SSH Key to GitHub
-
Log into GitHub -> Settings -> SSH and GPG keys
- Copy the key to clipboard and Paste
Create your own repo on Github
Create your own repo on Github (cont.)
-
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} git@github.com:{UserName}/members.git
-
Save your local commited changes to the remote repository
git push -u {name} {branch name}
Making a Commit (Adding to README)
Fixing a Merge Conflict (cont.)
Fixing a Merge Conflict (cont.)
-
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……“
Fixing a Merge Conflict (cont.)
Working on Branches + a Pull Request
Branching + Pull Request
-
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
Items Still Not Covered
- 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