Your first instinct, when you start to do something new, should be
git init. You’re starting to write a new paper, you’re writing a bit of code to do a computer simulation, you’re mucking around with some new data … anything: think
A new repo from scratch
Say you’ve just got some data from a collaborator and are about to start exploring it.
- Create a directory to contain the project.
- Go into the new directory.
- Write some code.
git addto add the files.
The first file to create (and add and commit) is probably a ReadMe file.
A new repo from an existing project
Say you’ve got an existing project that you want to start tracking
- Go into the directory containing the project.
git addto add all of the relevant files.
- You’ll probably want to create a
.gitignorefile right away, to indicate all of the files you don’t want to track. Use
git add .gitignore, too.
Connect it to github
You’ve now got a local git repository. You can use git locally, like
that, if you want. But if you want the thing to have a home on github, do
- Go to github.
- Log in to your account.
- Click the new repository button in the top-right. You’ll have an option there to initialize the repository with a README file, but I don’t.
- Click the “Create repository” button.
Now, follow the second set of instructions, “Push an existing repository…”
$ git remote add origin firstname.lastname@example.org: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
email@example.com:username/new_repo rather than
https://github.com/username/new_repo, as the former is for use with ssh. If you use the latter construction, you’ll have to type your github password every time you push to github.