title | subtitle | author | job | logo | framework | highlighter | hitheme | url | widgets | mode | |||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Basic Git Commands |
Jeffrey Leek, Assistant Professor of Biostatistics |
Johns Hopkins Bloomberg School of Public Health |
bloomberg_shield.png |
io2012 |
highlight.js |
tomorrow |
|
|
selfcontained |
- Once you have a repository, you'll probably make changes over time
- Often, you'll want to share these changes with others (users, followers, collaborators, etc.)
- Git allows you to track your changes locally (on your computer)
- GitHub allows you to share your changes with the world (or just a few people, depending on whether your repo is public or private)
- But how to communicate between Git and GitHub?
- First we'll review some basic commands, then we'll look at a typical workflow
http:https://gitready.com/beginner/2009/01/21/pushing-and-pulling.html
- Suppose you add some new files or make changes to a local repository (on your computer)
- You need to let Git know that you want it to pay attention to these files (i.e. "track" these files)
- From the directory where the repo is located on your computer (in Git Bash or Terminal, depending on whether you're on Windows or Mac, respectively):
git add .
adds all new files (note the period afteradd
, which represents "all files")git add -u
updates tracking for files that changed names or were deletedgit add -A
orgit add --all
does both of the previous
- You want to organize and save "snapshots" of the files you've staged for commit
- You type the command
git commit -m "your message goes here"
, substituting a useful description (between the double quotes) of what changes you made since the last committed changes
- This only updates your local repo, not the remote repo on GitHub
- To see a log of the commits you've made locally, type
git log
- Spacebar advances page by page
- Return advances line by line
- Typing the letter "Q" exits the log
- Once you are pleased with your local commits, you would like to update the remote repo (on GitHub)
- The command
git push
sends your most recent commits to GitHub, updating your remote repository for the world to see
- If you fork someone else's repo and make some changes or additions, you may want the original author to merge your changes into their code
- To do so you need to issue a pull request via GitHub
- Don't need anyone's permission to fork and make changes, but the original author is not obligated to accept your changes
- Pull requests offer a powerful means of contributing to open source software
- Git documentation http:https://git-scm.com/doc
- Github help https://help.github.com/
- Google/Stack Overflow are great for Github