You are not logged in.

#1 2009-11-04 11:36:36

Gen2ly
Member
From: Sevierville, TN
Registered: 2009-03-06
Posts: 1,529
Website

github help: Howto maintain a repo?

I've put the bash scripts I have on a github account and I update them from time to time.  However, when I tried to update today, I got:

To git@github.com:Gen2ly/home.git                                               
 ! [rejected]        master -> master (non-fast forward)                        
error: failed to push some refs to 'git@github.com:Gen2ly/home.git'             
To prevent you from losing history, non-fast-forward updates were rejected      
Merge the remote changes before pushing again.  See the 'non-fast forward'      
section of 'git push --help' for details.

I'd like to keep my bash scripts and the github repository in sync (so they match and there are no extraneous files).  The process I'm using now:

cd ~/.github-home
rsync -a --delete --force --exclude='programs/warehouse' --exclude \
'root/warehouse' --exclude 'warehouse' $HOME/.bin .
git add .
git commit -a -m "commit message"
git reset --hard    # reset current branch so it to matchs githubs on sync
git push github master

This worked fine until today when I got the '...non-fast-forward updates were rejected' message.  What do I need to be doing here?  Also any experts that know more about git and have any advice, I'd appreciate hearing it.

Last edited by Gen2ly (2009-11-04 11:38:21)


Setting Up a Scripting Environment | Proud donor to wikipedia - link

Offline

#2 2009-11-04 12:11:23

foutrelis
Developer
From: Athens, Greece
Registered: 2008-07-28
Posts: 705
Website

Re: github help: Howto maintain a repo?

First of all, `git reset --hard' doesn't do anything as there are no pending local changes (you've committed them in the previous step) and you're not specifying a commit to reset to so it picks HEAD which is the commit you're currently at. It is considered a powerful (read dangerous) command, and is mostly used for throwing away unwanted uncommitted changes.

To understand the non-fast forward error you're receiving, do a `git help push' and read the section titled "NOTE ABOUT FAST-FORWARDS". I'm not sure what the exact situation of your local repository is, but `gitk' may be able to give you a visual indication of where your local branch has diverged and causes the push to not be fast forward.

Git has awesome man pages. When you're in doubt, `git help <command>' comes in handy. smile

Offline

#3 2009-11-04 17:07:52

Gen2ly
Member
From: Sevierville, TN
Registered: 2009-03-06
Posts: 1,529
Website

Re: github help: Howto maintain a repo?

foutrelis wrote:

To understand the non-fast forward error you're receiving, do a `git help push' and read the section titled "NOTE ABOUT FAST-FORWARDS". I'm not sure what the exact situation of your local repository is, but `gitk' may be able to give you a visual indication of where your local branch has diverged and causes the push to not be fast forward.

When you're in doubt, `git help <command>' comes in handy. smile

Git does has awesome man pages. Still not sure how this happened though as I'm the on person on the project.  Did a 'git push --force' that fixed it but lost my history which I guess isn't a big deal. 

foutrelis wrote:

First of all, `git reset --hard' doesn't do anything as there are no pending local changes (you've committed them in the previous step) and you're not specifying a commit to reset to so it picks HEAD which is the commit you're currently at. It is considered a powerful (read dangerous) command, and is mostly used for throwing away unwanted uncommitted changes.

Ok, so how do I then do a git push that will assure that the local and remote repository are in sync (i.e. deleted folders... that have been erased on the local are also not on the remote repository)?  Before I was getting old scripts and such that I had deleted being left on the github repository.  The 'git reset --hard' seems to have fixed it as I'm pretty sure I didn't do any other changes after I added that, but maybe it was something else?

Last edited by Gen2ly (2009-11-04 17:08:54)


Setting Up a Scripting Environment | Proud donor to wikipedia - link

Offline

#4 2009-11-04 18:55:29

foutrelis
Developer
From: Athens, Greece
Registered: 2008-07-28
Posts: 705
Website

Re: github help: Howto maintain a repo?

Gen2ly wrote:

Ok, so how do I then do a git push that will assure that the local and remote repository are in sync (i.e. deleted folders... that have been erased on the local are also not on the remote repository)?  Before I was getting old scripts and such that I had deleted being left on the github repository.  The 'git reset --hard' seems to have fixed it as I'm pretty sure I didn't do any other changes after I added that, but maybe it was something else?

It's difficult to say without having the repo to poke at it. The "-a" switch you pass to `git commit' should remove any files that are not present in the working directory from the repository and then `git push' will push your commits to the remote repository (which is a "bare" repo, in the sense that it doesn't keep any checked out files, only the contents of the .git directory).

I use the "status", "diff", "diff --cached" and "log" commands quite often, especially before committing. They give you a good overview of the changes you're about to add to the repository (staged changes that have been added to the index) and changes which will not be committed (unstaged changes that exist in your working directory but have not been added to the index).

Offline

#5 2009-11-04 19:09:34

rson451
Member
From: Annapolis, MD USA
Registered: 2007-04-15
Posts: 1,233
Website

Re: github help: Howto maintain a repo?

I've only worked with git for a short while, but it was explained to me that you get errors about fast-forward commits when there is a commit on the remote  that is not in your working copy.

Are you working on this from multiple machines or from multiple different local copies?  If so, then it's possible you committed something and pushed to the remote from one copy, then never pulled those changes in from your other copy.


archlinux - please read this and this — twice — then ask questions.
--
http://rsontech.net | http://github.com/rson

Offline

#6 2009-11-05 19:27:58

Gen2ly
Member
From: Sevierville, TN
Registered: 2009-03-06
Posts: 1,529
Website

Re: github help: Howto maintain a repo?

No, did all my uploads from one machine.  However since the last time I did it, I've done a reinstall which I am thinking accounted for it.  I'm thinking ~/.git keeps track of changes and may it was not finding a matching record (?) and then wouldn't allow the update.


Setting Up a Scripting Environment | Proud donor to wikipedia - link

Offline

#7 2009-11-06 15:21:28

falconindy
Developer
From: New York, USA
Registered: 2009-10-22
Posts: 4,111
Website

Re: github help: Howto maintain a repo?

Ahh, if you did a reinstall you just need to recreate your remote (as you did in the initial setup e.g. git remote add origin git@github.com:user/repo.git) and then do a 'git pull' to gather your history before making further changes.

Last edited by falconindy (2009-11-06 15:22:00)

Offline

Board footer

Powered by FluxBB