Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use git to sync code without committing?

I use egit in Eclipse to sync my code between two locations using a repository on bitbucket.

I want to be able to work on the code from either location. What I usually do is commit the changes at the end of the day.

Is there another way I should be doing this, as I end up with a lot of commits for code that I'm still working on that is still broken?

I thought the idea was that you are meant to only commit when the code is working. What is best practice so I can update the code in the repository without committing, and only commit when the code is working?

like image 748
localhost Avatar asked Nov 23 '14 23:11

localhost


People also ask

Is there a git-sync command?

git-sync is a simple command that pulls a git repository into a local directory.

Can we push code without commit?

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

How do I sync my repository?

To re-synchronize your local repository with the newly updated remote repository, simply run the git pull operation. When the pull is executed, the latest revision history will download from the remote repository and import to your local repository. Pull changes from a remote repository to your local repository.


2 Answers

If you use Linux Terminal, you can use rsync command. The follow answer is copy from my other answer

Just Use rsync command. Make sure you are in your local repo root path, and run:

rsync -a --exclude=.git . [email protected]:[Your Remote Path]

You can fix your code in local, and rsync it. When the code can be deploy, then commit the deploy issue.

You can config your ssh remote alias in ~/.ssh/config file, google to know how to config it. Then your command will be:

rsync -a --exclude=.git . [remote-alias-name]:[Your Remote Path]

And needn't enter password.

like image 183
MistKafka Avatar answered Oct 21 '22 23:10

MistKafka


Before you start, create a separate (feature) branch and checkout to it. Now you can commit whatever you want, be it a broken code or just some experiment. You can also fetch your master branch (or dev etc.) and rebase on top of it (or dev etc.) to keep your branch up to date. As soon as you get the code to the final state, use interactive rebase* to clean up / squash / reorganize your commit history and merge with the main branch.

*You can also use git reset (with mixed mode) to the point where your feature branch branched off and create a brand new commit.

like image 24
Jiří Pospíšil Avatar answered Oct 22 '22 00:10

Jiří Pospíšil