Chapter 14. How Do I…?
This final chapter presents some commands and recipes for accomplishing a grab bag of specific tasks. Some were presented earlier and are repeated or referred to here for easy reference, and some are new. Remember that you don’t usually want to edit history for commits you’ve already published with git push. Examples that refer to a remote repository use the most common case, origin. rev is any revision name as described in Chapter 8.
…Make and Use a Central Repository?
Suppose you have an account named ares on a server mars.example.com, which you want to use to coordinate your own work on a project foo (perhaps among repositories at home, work, and on your laptop). First, log into the server and create a “bare” repository (which you will not use directly):
$ ssh ares@mars.example.com ares> git init --bare foo Initialized empty Git repository in /u/ares/foo/.git $ logout
If this is for a project with existing content, connect that repository to the new remote as its origin (assuming here a single, local master branch):
$ cd foo $ git remote add origin ares@mars.example.com:foo $ git push -u origin master ... To ares@mars.example.com:foo * [new branch] master -> master Branch master set up to track remote branch master from foo.
You can just use plain git push from then on. To clone this repository elsewhere:
$ git clone ares@mars.example.com:foo…Fix the Last Commit I Made?
Make your corrections and stage them with git add, then:
$ git commit --amendAdd -a to automatically ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access