Caching Github login credentials

Thursday, 7. May 2015

If you are new to Github and you are cloning your repository via HTTPs url, you will notice that Git will prompt you to specify login and password everytime you try to pull or push your changes to and from GitHub.

Obviously this is not ideal (especially if you push and pull often). Luckily as of Git 1.7.10 or newer you can use the credential helper feature to cache credentials for a specified time. This means, you only have to specify your login details once and git will cache those for the time duration you specify

To achieve this, all you need it to run the following command on your terminal window and you are done! Time is in seconds incase you want to change to something that works for you!

git config --global credential.helper 'cache --timeout=7200'
# Set the cache to timeout after 1 hour (setting is in seconds)

Hope this helps someone! Comments below if you have something better!

src refspec master does not match any : failed to push some refs

Thursday, 7. February 2013

I have had this error after moving repository to another account. There are various factors that may cause such problem but since I was sure our git framework covered all the basics, i was a little suprised as to why I keep having this issue.

error: src refspec master does not match any.
error: failed to push some refs to '/path/repo.git'

After a bit of cross referencing, I indeed notice the head information was not being created when we initiated repository under the new account under (your_repo.git/refs/heads)

In the end it turned out the issue was simply because there was no user details registered in git config for the account we were currently using. So afterall the frameworks was not covering all the basics by the looks of things!! :)

Anyway, to solve it.. simply add the following basic details and you will be sorted

git config --global "YOUR NAME"
git config --global "YOUR EMAIL"

git: pull is not a git-command. See git –help

Wednesday, 7. November 2012

I have come across this error on my server

git: 'pull' is not a git-command. See 'git --help'
Did you mean this?

After some time of debugging, I came to realize the problem is actually due to missing files in git core folder for this current account

To solve this.. Run the following command on the terminal

git --exec-path

Make sure the path displayed exists on your current user account. If not, then copy the files from the account with Git installation that works perfectly to this user account. You will need to create that directory structure of course!


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.