Git Lifecycle: Preserve Your Own Work

At this point, you've been working all day on your project (or an hour or two) and you'd like to safeguard what you've done. Make sure that HEAD points at your private branch (if it doesn't, you're in big trouble):

$ git branch master * jack

Look at what your remote repository is. This is the one you started from when you cloned. Git echoes that the servername of the back-end repository is acme.

$ git remote -v origin [email protected]:rest-server (fetch) origin [email protected]:rest-server (push)

So, you're free to push your own branch work to that location:

$ git push -u origin jack

This pushes your work to the remote repository to save it under the same name and you can afterward update the jack branch at the server with what's in your local copy any time you think you have something to keep safe. Thereafter, however, you may just type the following because it's already set up:

$ git push

Extra credit: saving your branch work still elsewhere

If you're converting to use a different back-end repository, you would do the following to accomplish this. The new host here is named goopyface.

$ git push [email protected]:rest-server jack

What if you're harrassed by colleagues that do not like your choice of branchname?

  1. Rename the local branch:
    $ git branch -m new-name
  2. Remove the remote branch by its old name, then push the local to remote under the new name:
    $ git push origin :old-name new-name
  3. Reset the upstream branch for use by the local under the new name:
    $ git push origin -u new-name