Solved – git push – Your branch is ahead of origin/master by x commits

Sunday, 28. October 2012

For those starting to use Git in a team or group of collaborators, it’s common to come across this error when trying to puch changes over to your git server repository. – Your branch is ahead of ‘origin/master’ by x commit

Basically, what git is trying to tell you here is that you are trying to upload changes to a repository that has recent changes than those on your local repository

So the best thing to do here in order to get a successful push, you will simply need to consolidate the two repositories. There are sevaral ways to achieve this consolidation or merging process

1) Using Git Pull
Git pull allows you to automatically fetch (download) changes and fix them automatically. Git pull is context sensitive, which means git try to will merge any pulled (downloaded) commits from remote repository into the branch you are currently working in and automatically merge the commits without letting you review them first. This can be scary process but a quick solution

git pull <repo_name>

2) Using Git fetch
Sometimes it is important to have control over what changes needs to be final for any conflicting file. In order to have such control, you will need to use git fetch and merge commands to achieve this

Git fetch does one cool thing: As opposed to git pull, git fetch will pull down the remote repo and try to merge changes in the current working branch. However, if it encounters the differences in any file, it will report a failure and tell you which files happen to be in conflict.

At this stage, git provides you with an opportunity to review the files in question and decide which which changes should be final for that file.

There are fine tools our there such as gitk, ViewGit etc that can help you to visually checkout the conflicts and decide what to do.

To Fetch the repo you may want to specify RefSpecs for git to be more specific on which repository and branch you want to fetch and merge your current branch with. You can also set default RefSpecs in your .git/config file if you will always be fetching and merging from the same source and destination.

# fetch origin repo and try to merge local master branch with Master branch from origin repo
git fetch origin master:refs/remotes/origin/master
# the merge the stuff from origin repo with current branch
git merge origin

At this level, any conflicts detected will need to be fixed and once you have them changes figured out and fixed, you will then need to add all the changes to the current branch ready for commit

# add all files in the working tree and mark them for commit
git add .
# them commit your changes locally
git commit -a
# push changes to remote
git push <remote_repo> <local_repo>

Failed to push some refs to git server non-fast-forward updates were rejected

Saturday, 27. October 2012

If you have ever come across such errors as this below while pushing your changes to your git server repository..

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

It will be because Git with all it’s wisdom, is trying to save your bits as it has detected there are changes to the repository you are pushing stuff too that could be lost should you continue. This could happen if someone else is accessing and/or trying to update the same branch of the same repository you are trying to update.

To solve such problem you can either

– Fetch and merge the remote repo manually.
– Use “git pull” to both fetch and merge insentiences at once then – git push your changes.
– Finally, you can use the –force flag to tell git to simply overwrite the stuff.

However, the later should be the least recommended approach and only use it if you are the only one using the remote repository or you are sure nothing will actually be lost on that branch.

Enjoy gittin’!

Cannot update the ref refs-remotes-origin-master – git server

Saturday, 27. October 2012

Every now and then you may encounter the following errors while pushing stuff to your git server.

error: unable to create directory for .git/logs/refs/remotes/origin/master
error: Cannot update the ref 'refs/remotes/origin/master'.

The underlining issue here is with your folder permissions where your local (bare) repository dwells. Update permissions on .git folder or use a user account with write permissions on this folder.


Show Delete Shared Folder resources On Ubuntu/Linux System

Tuesday, 23. October 2012

A little snippet to show and delete currently shared folders or resources on Ubuntu / Linux machine.

Show Shared folders / resources

net usershare info

Delete Shared folders / resources

net usershare delete <share_name>


Find URLs in Text description With Regex PHP

Saturday, 20. October 2012

This little regex script gives you another simple way to fetch for all possible URLs embedded as simple text in a your rather large description text.

It’s flexible and you can add more filters appropriate for your requirement as you wish..

# take it to the test!
$matches = null;
$returnValue = preg_match_all('%(https://|http://|www)[a-zA-Z0-9\/#&-_\.]+%', $desc_variable, $matches);
# see what you got!


Can’t save customer – call_user_func Zend Validate Hostname Com getCharacters

Thursday, 18. October 2012

A rather strange error on live server happened when customers try to register an account they get and error message “Can’t save customer”.

After a bit of digging and throwing lots of exceptions – came to find the solution as explained below..

** HANG ON – Ideally you will want to make these changes on your local folder. Please don’t edit the core files **

Go to file: lib/Zend/Validate.

Scroll down to around line 324 where you will spot a script similar to:

     if (Zend_Loader::isReadable($classFile)) {

Replace that line with:

     if (file_exists($classFile) && Zend_Loader::isReadable($classFile)) { 
      # added: file_exists($classFile) &&