Your first instinct, when you start to do something new, should begit init
. You’re starting to write a new paper, you’re writing abit of code to do a computer simulation, you’re mucking around with somenew data … anything: think git init
.
A new repo from scratch
Say you’ve just got some data from a collaborator and are about tostart exploring it.
- Create a directory to contain the project.
- Go into the new directory.
- Type
git init
. - Write some code.
- Type
git add
to add the files (see thetypical use page). - Type
git commit
.
The first file to create (and add and commit) is probably a ReadMefile, either as plain text or withMarkdown, describingthe project.
Markdown allows you to add a bit of text markup, likehyperlinks,bold/italics, or to indicate code with a monospacefont
. Markdown is easily converted to html for viewing in a webbrowser, and GitHub will do this for you automatically.
A new repo from an existing project
Say you’ve got an existing project that you want to start trackingwith git.
- Go into the directory containing the project.
- Type
git init
. - Type
git add
to add all of the relevant files. - You’ll probably want to create a
.gitignore
file right away, toindicate all of the files you don’t want to track. Usegit add.gitignore
, too. - Type
git commit
.
Connect it to github
You’ve now got a local git repository. You can use git locally, likethat, if you want. But if you want the thing to have a home on github, dothe following.
- Go to github.
- Log in to your account.
- Click the new repository button in thetop-right. You’ll have an option there to initialize the repository with a READMEfile, but I don’t.
- Click the “Create repository” button.
Now, follow the second set of instructions, “Push an existingrepository…”
$ git remote add origin git@github.com:username/new_repo$ git push -u origin master
Actually, the first line of the instructions will say
$ git remote add origin https://github.com/username/new_repo
But I use git@github.com:username/new_repo
rather than https://github.com/username/new_repo
, as theformer is for use withssh (if you set up ssh asI mentioned in “Your first time”, then you won’thave to type your password every time you push things to github). Ifyou use the latter construction, you’ll have to type your githubpassword every time you push to github.