Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pushing without a commit in Mercurial or Git

Seems like for both Mercurial or Git, if I don't commit first, then I can't push?

So if I don't commit (when not ready yet), I can't push to a remote server to back up my code? The code is in a notebook computer, being carried around, which can be somewhat fragile being carried around.

like image 685
nonopolarity Avatar asked Sep 08 '10 05:09

nonopolarity


People also ask

Can you git push without committing?

No, you must make a commit before you can push. What is being pushed is the commit (or commits).

Do I need to commit before push?

Yes, you do need add and commit your changes before pushing your code to your github repository.

Is push and commit same?

Commit - committing is the process which records changes in the repository. Think of it as a snapshot of the current status of the project. Commits are done locally. Push - pushing sends the recent commit history from your local repository up to GitHub.


1 Answers

You are always ready to commit.

Commit often. Commit to a work in progress branch and distribute it as widely as you feel.

When you get to the state that you're currently referring to as "ready to commit", examine the divergence of your branch from the upstream, do a rebase -i to clean it up and make it look like you want.

This will be easier, safer, and just generally give you better results than trying really hard to get everything perfect before committing. Remember: A commit doesn't necessarily represent a desired permanent state of the universe. It's just somewhere you are. How you publish it is up to you.

git makes it very easy to publish a do-not-look-at-me branch for your work in progress that you can later move into your official codebase at whatever point and in whatever form you think best suits you.

like image 118
Dustin Avatar answered Sep 23 '22 17:09

Dustin