|
| 1 | +--- |
| 2 | +layout: page |
| 3 | +title: Start a new git repository |
| 4 | +--- |
| 5 | + |
| 6 | +Your first instinct, when you start to do something new, should be |
| 7 | +`git init`. You're starting to write a new paper, you're writing a |
| 8 | +bit of code to do a computer simulation, you mucking around with some |
| 9 | +new data ... _anything_: think `git init`. |
| 10 | + |
| 11 | +### A new repo from scratch |
| 12 | + |
| 13 | +Say you've just got some data from a collaborator and are about to |
| 14 | +start exploring it. |
| 15 | + |
| 16 | +- Create a directory to contain the project. |
| 17 | +- Go into the new directory. |
| 18 | +- Type `git init`. |
| 19 | +- Write some code. |
| 20 | +- Type `git add` to add the files (see the |
| 21 | + [typical use page](routine.html)). |
| 22 | +- Type `git commit`. |
| 23 | + |
| 24 | +The first file to create (and add and commit) is probably a ReadMe |
| 25 | +file, either as plain text or with |
| 26 | +[markdown](http://daringfireball.net/projects/markdown/), describing |
| 27 | +the project. |
| 28 | + |
| 29 | + |
| 30 | +### A new repo from an existing project |
| 31 | + |
| 32 | +Say you've got an existing project on which you've not been using |
| 33 | +version control, and you want to start. |
| 34 | + |
| 35 | +- Go into the directory containing the project. |
| 36 | +- Type `git init`. |
| 37 | +- Type `git add` to add all of the relevant files. |
| 38 | +- You'll probably want to create a `.gitignore` file right away, to |
| 39 | + indicate all of the files you don't want to track. Use `git add |
| 40 | + .gitignore`, too. |
| 41 | +- Type `git commit`. |
| 42 | + |
| 43 | + |
| 44 | +### Connect it to github |
| 45 | + |
| 46 | +You've now got a local git repository. You can use git locally, like |
| 47 | +that, if you want. But if you want the thing to have a home on github, do |
| 48 | +the following. |
| 49 | + |
| 50 | +- Go to [github](http://github.com). |
| 51 | +- Log in to your account. |
| 52 | +- Click the [new repository](https://github.com/new) button in the |
| 53 | +top-right. You'll have an option there to initialize the repository with a README |
| 54 | +file, but I don't. |
| 55 | +- Click the “Create repository” button. |
| 56 | + |
| 57 | +Now, follow the second set of instructions, “Push an existing |
| 58 | +repository...” |
| 59 | + |
| 60 | + $ git remote add origin git@github.com:username/new_repo.git |
| 61 | + $ git push -u origin master |
| 62 | + |
| 63 | +Actually, the first line of the instructions will say |
| 64 | + |
| 65 | + $ git remote add origin https://github.com/username/new_repo.git |
| 66 | + |
| 67 | +But I've found that the `https://github...` bit doesn't work and I |
| 68 | +need to use `git@github...` I don't really understand the difference. |
0 commit comments