3

I'm working on an Android project with my colleague and he recently setup a GitHub repo on https://github.com. At my end, I downloaded and installed GitHub for Windows on my 64-bit Windows 7 machine. I then proceeded to go to the repo on GitHub and clone the project using the 'Clone in Windows' button.

Clone in Windows

Everything appeared to go smoothly and the project was at

C:\Android\git-repos\OurProject

on my machine. I then made some changes to the file

C:\Android\git-repos\OurProject\Host\Android\src\com\ourproject\client\SettingsActivity.java

I then observed that the changed file (along with some changed build files) did show up on the version of GitHub I had on my machine like this

http://s11.postimage.org/k8o91hq37/changes_on_github.png

I selected the 'SettingsActivity.java' file, filled in a short description and hit the 'Commit' button. Then I saw the following screen

http://s16.postimage.org/yier6czf9/unsynced_commits.png

Then, when I clicked on 'sync'

sync

hoping the changes I made would be pushed back to the master repo, I got the following message

unstaged changes
You cannot sync with unstaged changes. Please commit your changes and try again.

Why did I get this error message?

I did look at this thread

What's the unstaged changes in github?

and it seems that one has to do the following steps

  1. git add
  2. git commit
  3. git push

but from this thread

What does GitHub for Windows' "sync" do?

it might appear that the 'sync' button does all three? So, I'm not sure how to exactly stage my commits. I thought the fact that I had committed my changes (in the previous step) implied that I had staged them and that is why the option to sync was being offered. Any help in resolving this issue would be much-appreciated.

P.S: I also reached out to the GitHub support team and have posted their solution below as well.

2 Answers 2

7

Just to add to what VonC wrote...

Each time I attempted to hit the 'sync' button, I was shown the following screen

Unstaged Changes

After reading what he suggested, I clicked on 'Open Shell' and typed

git stash

and it displayed something like this

Power Shell

After this I was able to hit the 'sync' button and it was able to sync successfully.

Added After Reading VonC's Comment

However, after adding that file successfully to the repo, I noticed that the other two build files ('BuildConfig.java' and 'project.properties') were not showing up in GitHub for Windows. So, after reading VonC's suggestion, I typed

git stash pop

in the shell that was opened earlier and then the two files appeared again on GitHub for Windows.

Added After Hearing Back from GitHub Support

Unfortunately you can't sync while you have unstaged changes or files. But there is one workaround:

  1. Commit everything in your working directory (use a commit message of "WIP" or something as short for "Work in Progress")
  2. Sync.
  3. Select the "WIP" commit and click the "rollback to this commit" button.

When you sync, local commits are taken and put at the end of the commits you got from the server.

12
  • 1
    Good feedback and illustrations. +1 Don't forget a git stash pop to re-apply your work in progress on your (now sync'ed) working tree. And consider setting core.autocrlf to false (stackoverflow.com/questions/2825428/…).
    – VonC
    Oct 29, 2012 at 7:23
  • Thank you. I'll be sure to update the answer above to reflect the use of stash pop. I'll also look into core.autocrlf.
    – aLearner
    Oct 29, 2012 at 10:07
  • So I tried to look into core.autocrlf but I'm not sure I fully understand how to do this. :-/
    – aLearner
    Oct 29, 2012 at 10:38
  • The idea is to make sure git doesn't change anything (in term of newline style) unless you explicitly (as, for instance, in stackoverflow.com/a/10855862/6309) configured Git to do so: stackoverflow.com/questions/2333424/…. So : git config --global auto.corecrlf false
    – VonC
    Oct 29, 2012 at 10:39
  • Cool. Thank you for the information and the useful references. This is really helpful.
    – aLearner
    Oct 29, 2012 at 11:26
1

You have committed a file, but not all files.
You wouldn't be able to sync with a working tree including some changes in progress.
Said changes need to be stashed, (command-line only, according to "GitHub - Unsynchronized Commit?"), or committed first (as described in this gist).

3
  • Thank you. So, does this mean that I need to commit all files for it to be able to sync?
    – aLearner
    Oct 29, 2012 at 6:51
  • @aLearner commit or stash (kernel.org/pub/software/scm/git/docs/git-stash.html), but since a pull is involved, Git will need a clean working tree in order to realize the sync.
    – VonC
    Oct 29, 2012 at 6:53
  • Thank you so much! This really did the trick. I'll post a more detailed reply to add to what you wrote above.
    – aLearner
    Oct 29, 2012 at 7:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.