Skip to content

Instantly share code, notes, and snippets.

@biglovisa
Last active December 4, 2019 15:52
Show Gist options
  • Save biglovisa/cec6a34fa88293e7e1c37f57bde44a72 to your computer and use it in GitHub Desktop.
Save biglovisa/cec6a34fa88293e7e1c37f57bde44a72 to your computer and use it in GitHub Desktop.
git
# Git
## Source control
- Keep historical log of what has changed
- Helps when you want to collaborate with other people
- Safer way to ship software
## Concepts
- Commit (sha, message, author, changes)
- Branches (master branch/feature branch)
- Remote (usually origin)
- Fork
- HEAD
## Commands
- git status
- git add (., -p)
- git commit (-m)
- git stash
- git checkout (-b, filename)
- git reset (--hard, <sha>/HEAD~<n>)
- git rebase (-i)
- git merge
- git diff (--cached)
- git log
- git show
- git bisect
## In teams
- Communication
- Small, atomic changes will speed things up
- Self comments on PR before asking for a review
- You are not your code
- Words and tone matter a lot
- Prefer syncing up in person vs discussing online forever
## Workflows
- Keep a short distance from the latest commit
- Commit when something is working
- Descriptive commit messages
- Don't rebase master into your branches when working with other people
- One PR, one commit
- Small PRs
- Provide all the information in PRs (use a PR template!)
- Commit often, and then rebase interactively
https://twitter.com/biglovisa/status/1163511586738311168
### Exercises
1. Initialize a new git repository locally on your command line.
2. Create a new repository on github
3. Locally on your computer in the repository you created, set the remote to point to the repository you created on Github.
4. Locally, create a file and put some content in it.
5. Push up the commit to Github and verify you can see your changes in Github.
6. Make another change, create a commit for it and push it up to Github.
7. Make another change in the same file you recently changed. Amend those changes to the latest commit.
8. Push up those changes to Github.
9. Check out a new branch.
10. Make a change. Push up those changes to Github.
11. Create a pull request.
12. Merge the pull request. Check out master locally, and pull down those changes.
13. Create another branch, make a change in an existing file, push it up, merge them to master through a pull request.
14. DO NOT PULL DOWN YOUR CHANGES. Check out a fresh branch, make a change in the file you just touched.
15. Check out master, and pull down your changes.
16. Check out the branch you just created. Merge master. Hopefully you just created your first merge conflict, fix it :)
https://twitter.com/biglovisa/status/1163511586738311168
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment