Skip to content

Committing changes in Git

chrisadolph edited this page Feb 26, 2012 · 1 revision

Suppose you have a local clone of the tile-simcf repository on your disk. You've modified a few files, and think your code is ready for the rest of the team to look at, or even pull in to the master repository. Here's how you commit your changes to your online Github repository so the rest of us can see them. These instructions assume you are using git from the command line, but there are GUI alternatives.

Preliminaries

You will need to open a terminal, and change your directory to the location of your local Git repository.

You will also need to make sure git knows the location you want to commit your changes to. Usually, you will want to commit your changes to your "origin", which is your online repository (replace YOURNAME with the appropriate Github userid):

git remote add origin [email protected]:YOURNAME/tile-simcf.git

You can create different locations besides origin, e.g., you might do

git remote add chris [email protected]:chrisadolph/tile-simcf.git

to send stuff to my repository, though normally you'd send stuff to your own repository (origin), and then send a pull request to me through Github.

You only need to set the origin (or any other location) once; Git will remember.

Checking for, reviewing, and staging changes

To check for changes in your repository, you can type

git diff

which list (rather laboriously) every addition and deletion of a line to any tracked file; this set is optional. Next, to confirm these changes, you "stage" them. This can be done interactively, using

git add -i

Staging is a great way to keep a permanent record of a "waypoint" in your code development, even if you aren't sure yet that the code is worth uploading and sharing as a new commit. This could be a way to save a version of some tricky code in case you want to go back, or simply something you do after you are finished coding for the night to save your place.

Committing changes locally and pushing new commits to github

The next step is to commit your changes as a new version in your local repository. You will need to provide a brief but informative summary of your changes, like so:

git commit -m "Fix fontface in mlogit, simplify lineplot example, add cfFactorial example, fix fontface in traces"

This makes a new commit on your computer, but not on the web, so the last step is to actually send your new commit to Github. To send your new commit to the origin, just do:

git push

but you could also send to a different specific location set using git remote add. For example, if you made the remote location chris using the code above, you might try pushing to chris using:

git push chris