|
| 1 | +--- |
| 2 | +title: "Pushing to GitHub" |
| 3 | +--- |
| 4 | + |
| 5 | +Git is a version control system. It allows you to keep the entire history of your code, and makes it easy to share and collaborate with others. |
| 6 | + |
| 7 | +### Using git |
| 8 | + |
| 9 | +Using git is really easy: |
| 10 | + |
| 11 | +1. Set up a folder to be a _git repo_. This tells git to track all changes in that folder. |
| 12 | +2. After you've made some changes, save them into the repository. |
| 13 | +3. Once you've saved the changes push them up to github. |
| 14 | + |
| 15 | +The first point is important: *git works on a folder level*. It tracks all the changes you make to files within a given folder. |
| 16 | + |
| 17 | +### Actually using git |
| 18 | + |
| 19 | +Actually using git is a bit harder. It's a very powerful tool and pretty complex to get started with. To make things simpler, we're going to use a tool called `gitgit`. |
| 20 | + |
| 21 | +To install gitgit open the command line and type the following: |
| 22 | + |
| 23 | + gem install gitgit |
| 24 | + |
| 25 | +To see if this worked, type |
| 26 | + |
| 27 | + gitgit |
| 28 | + |
| 29 | +You should see a list of gitgit commands something like this: |
| 30 | + |
| 31 | + $ gitgit |
| 32 | + Commands: |
| 33 | + gitgit help [COMMAND] # Describe available commands or one specific command |
| 34 | + gitgit init # Initialise a git repo |
| 35 | + gitgit lg # Show your recent saves |
| 36 | + gitgit push # Push your changes to github |
| 37 | + gitgit save # Save you changes to the repo |
| 38 | + gitgit status # See what changes you've made since you last save |
| 39 | + |
| 40 | +If it didn't work, you might need to do |
| 41 | + |
| 42 | + sudo gem install gitgit |
| 43 | + |
| 44 | +and type your password. |
| 45 | + |
| 46 | +You also might need to do |
| 47 | + |
| 48 | + rbenv rehash |
| 49 | + |
| 50 | +If in doubt contact a teaching assistant! |
| 51 | + |
| 52 | +### Using gitgit |
| 53 | + |
| 54 | +To **make a folder into a git repository**: |
| 55 | + |
| 56 | + gitgit init |
| 57 | + |
| 58 | +then follow the instructions. You'll only need to do this once for each folder you want to make into a repository. |
| 59 | + |
| 60 | +After you've made some changes to your files and saved them, you can **save them into your repo** by typing: |
| 61 | + |
| 62 | + gitgit save |
| 63 | + |
| 64 | +Finally, to push your code up to github you can do |
| 65 | + |
| 66 | + gitgit push |
| 67 | + |
| 68 | +Before you do this, you will need to setup your repo with github. |
| 69 | + |
| 70 | +### Setting up your repo with github |
| 71 | + |
| 72 | +Go to github, login, and click "Create New Repo" in the top left hand corner. |
| 73 | + |
| 74 | + |
| 75 | + |
| 76 | +Follow the instructions, calling it something like `first_site`. **Do not** click the box which says 'Create a readme with this repository'. You'll get to a page when it'll describe how to get your code online. You want to follow the instructions for "Pushing an existing repository to github". |
| 77 | + |
| 78 | +### Pushing your code to github |
| 79 | + |
| 80 | +We will now set up your `first_site` folder to use git and push it up to github. |
| 81 | + |
| 82 | +{% exercise %} |
| 83 | +<ol> |
| 84 | +<li>Navigate to your first_site folder using cd and ls.</li> |
| 85 | +<li>Make it into a git repo: "gitgit init"</li> |
| 86 | +<li>Save all the work you've done so far: "gitgit save"</li> |
| 87 | +<li>Log in to GitHub.</li> |
| 88 | +<li>On github create a new repository called 'first_site'. DO NOT click the box which says 'Create a readme'.</li> |
| 89 | +<li>Copy and paste the instructions it gives you into the command line. You are 'Pushing an existing repository to github'.</li> |
| 90 | +<li>Go back to github and refresh the page. You should see your code.</li> |
| 91 | +</ol> |
| 92 | +{% endexercise %} |
0 commit comments