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
Say you’ve just got some data from a collaborator and are about to start exploring it.
git addto add the files (see the typical use page).
The first file to create (and add and commit) is probably a ReadMe file, either as plain text or with Markdown, describing the project.
Markdown allows you to add a bit of text markup, like hyperlinks, bold/italics, or to indicate code with a
monospace font. Markdown is easily converted to html for viewing in a web browser, and GitHub will do this for you automatically.
Say you’ve got an existing project that you want to start tracking with git.
git addto add all of the relevant files.
.gitignorefile right away, to indicate all of the files you don’t want to track. Use
git add .gitignore, too.
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 the following.
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 set up ssh as I mentioned in “Your first time”, then you won’t have to type your password every time you push things to github). If you use the latter construction, you’ll have to type your github password every time you push to github.
This page was last updated: 11-18-2019