git on mac osx: how to push filename cases to origin? - macos

I have changed the case of some directories in my git repository.
Then I pushed them and noticed the cases where not updated.
Then I found this question:
git mv and only change case of directory
I have followed the advice to use:
git add -A
git commit --amend -m 'updated cases'
git push origin
but instead of success the git server is returning:
To git#github.com:kyogron/example.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'git#github.com:kyogron/example.git'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes (e.g. 'git pull') before pushing again. See the
'Note about fast-forwards' section of 'git push --help' for details.
What can I now do to update the cases without breaking more in my git repo?
Regards,
bodo
PS: To avoid this issue in future you can use:
git config core.ignorecase false

You need:
git push --force
since you have rewritten the last SHA1 with your --amend, after using git mv.
It won't break your repo unless you have other collaborators having already pulled from your previous commit as explained in "How do I push amended commit to the remote git repo?".
(in that case, you would need other options for publishing your fixed commit)
On OsX, this answer does suggest (to avoid this issue):
git config --unset-all core.ignorecase
git config --system core.ignorecase false
The OP kyogron reports having found a working solution:
Create a new branch and checkout this new branch.
Then delete the .DS_Store file in the directory of the corrupted directory and rename it to new name.
Then remove wrong directory in the repository (you can view them with git ls-files) and commit this change.
Again remove the .DS_Store and now rename the directory to the lower case name you want with git mv

Related

git clone "you appear to have cloned an empty repository" but it's not empty, pull says "couldn't find remote ref master"

I'm trying to set up a vanilla new separate repository for the first time with git 2.37.1 on two W10 systems using drive mapping but I can't find any answered questions that fit my case given my novicitry. :-) Sorry the format is messed up, I did 4 spaces in front of code but most code lines ignore that for some reason.
Spent hours looking at other similar questions, but they all seem to say that there are no commits in the remote repository I'm trying to clone, which is not true. There are lots of commits.
I created a git repository on System1 and it works.
git ls-tree --full-tree --name-only -r HEAD
shows all my files (with lots of commits)
git show HEAD
shows
commit 557...27d (HEAD -> master)
# and the diff between the latest and previous commit
And
git branch -a
shows
* master
No branches, no complexity, no nothing
I go to System2, and create my repo directory, cd into it, then
git init
git remote add origin s:/cap2office # that's my mapped System1 repository)
git pull origin master
I get: fatal: couldn't find remote ref master
git remote
I get: origin
git branch -a
shows nothing
git ls-remote
shows: From s:/cap2office
I also tried:
git clone s:/cap2office
and it says
Cloning into 'cap2office'...
warning: You appear to have cloned an empty repository.
I know I'm missing some trivial magic command, but can't figure out what it is.
You are not cloning a repository, you are trying to clone the working directory of a git clone.
The git repository is stored in the .git folder inside the working directory.
Try this:
git remote add origin s:/cap2office/.git
On system 2, instead of doing git init then git remote add and git pull, do just this:
git clone s:/cap2office/.git
or if you're in Git Bash, sometimes the colon does not work so you need
git clone s/cap2office/.git
Then you can cd to the folder where it was cloned and do the usual git status, git checkout, change stuff, commit, and push to the remote.

GitHub Desktop Error: fatal: git show-ref: bad ref refs/tags/desktop.ini [duplicate]

Using git 1.6.4.2, when I tried a git pull I get this error:
error: unable to resolve reference refs/remotes/origin/LT558-optimize-sql: No such file or directory
From git+ssh://remoteserver/~/misk5
! [new branch] LT558-optimize-sql -> origin/LT558-optimize-sql (unable to update local ref)
error: unable to resolve reference refs/remotes/origin/split-css: No such file or directory
! [new branch] split-css -> origin/split-css (unable to update local ref)
I've tried git remote prune origin, but it didn't help.
Try cleaning-up your local repository with:
$ git gc --prune=now
$ git remote prune origin
man git-gc(1):
git-gc - Cleanup unnecessary files and optimize the local repository
git gc [--aggressive] [--auto] [--quiet] [--prune=<date> | --no-prune]
Runs a number of housekeeping tasks within the current repository, such as compressing file revisions
(to reduce disk space and increase performance) and removing unreachable objects which may have been
created from prior invocations of git add.
Users are encouraged to run this task on a regular basis within each repository to maintain good disk
space utilization and good operating performance.
man git-remote(1):
git-remote - manage set of tracked repositories
git remote prune [-n | --dry-run] <name>
Deletes all stale remote-tracking branches under <name>. These stale branches have already been
removed from the remote repository referenced by <name>, but are still locally available in
"remotes/<name>".
Happened to me as well. In my case, the bad ref was master, and I did the following:
rm .git/refs/remotes/origin/master
git fetch
This made git restore the ref file. After that everything worked as expected again.
This did the job for me:
git gc --prune=now
For me, it worked to remove the files that are throwing errors from the folder .git/refs/remotes/origin/.
I just would like to add one of the possible causes of a broken Git reference.
Possible root cause
On my system (Windows 7 64-bit), when a BSOD happens, some of the stored reference files (most likely currently opened/being written into when the BSOD happened) are overwritten with NULL characters (ASCII 0).
As others mentioned, to fix it, it's enough to just delete those invalid reference files and re-fetch or re-pull the repository.
Example
Error message:
cannot lock ref 'refs/remotes/origin/some/branch': unable to resolve reference 'refs/remotes/origin/some/branch': reference broken
Solution:
Delete the reference refs/remotes/origin/some/branch which is stored in the file %repo_root%/.git/refs/remotes/origin/some/branch.
Go to under flutter folder and then,
Try it:
git gc --prune=now
git remote prune origin
git pull
Explanation: It appears your remote repo (in GitHub / BitBucket) branches were removed ,though your local references were not updated and pointing to non existent references.
In order to solve this issue:
git fetch --prune
git fetch --all
git pull
For extra reading - Reference from Git documentation :
git-fetch - Download objects and refs from another repository
--all
Fetch all remotes.
--prune After fetching, remove any remote tracking branches which no longer exist on the remote.
Execute the following commands:
rm .git/refs/remotes/origin/master
git fetch
git branch --set-upstream-to=origin/master
Just in case, if you need to know what is
.git/refs/remotes/origin/master, you would read the Remotes section
in Git References.
In my case, the problem was solved after I've deleted all the remove reference files under the directory .git.
If you look at the message, it would tell you which files you need to delete (specifically).
The files to delete sit under .git/refs/remotes.
I've just deleted all the files there, and ran gc prune
git gc --prune=now
After that, everything works just fine.
git fetch --prune fixed this error for me:
[marc.zych#marc-desktop] - [~/code/driving] - [Wed May 10, 02:58:25]
[I]> git fetch
error: cannot lock ref 'refs/remotes/origin/user/janek/integration/20170505': 'refs/remotes/origin/user/janek/integration' exists; cannot create 'refs/remotes/origin/user/janek/integration/20170505'
From github.com:zooxco/driving
! [new branch] user/janek/integration/20170505 -> origin/user/janek/integration/20170505 (unable to update local ref)
From github.com:zooxco/driving
[marc.zych#marc-desktop] - [~/code/driving] - [Wed May 10, 02:58:30]
[I]> git fetch --prune
- [deleted] (none) -> origin/user/janek/integration
This assumes that the offending branch was deleted on the remote, though.
You can also add this to ~/.gitconfig to automatically prune when running git fetch:
[fetch]
prune = true
I had this same issue and solved it by going to the file it was erroring on:
\repo\.git\refs\remotes\origin\master
This file was full of nulls, I replaced it with the latest ref from github.
If this error “unable to update local ref” is reoccurring, even after applying either the answer by Vojtech Vitek or Michel Krämer you may you may have a bad ref on your local AND master repository.
In this case you should apply both fix's without pulling or pushing in between ...
rm .git/refs/remotes/origin/master
git fetch
git gc --prune=now
git remote prune origin
A permanent resolution for me was only achieved after applying both fix's before push/pull.
For me, I solved it this way:
rm .git/refs/remotes/origin/master
git fetch
After that I get this message from github.
There is no tracking information for the current branch
So next I did to fix this was:
git branch --set-upstream-to=origin/master master
git pull
To Answer this in very short, this issue comes when your local has some information about the remote and someone changes something which makes remote and your changes unsync.
I was getting this issue because someone has deleted remote branch and again created with the same name.
For dealing with such issues, do a pull or fetch from remote.
git remote prune origin
or if you are using any GUI, do a fetch from remote.
Try this:
git pull origin Branch_Name
Branch_Name, the branch which you are currently on.
If you do only a git pull, it pulls all other created branch name as well.
So is the reason you are getting this:
! [new branch] split-css -> origin/split-css (unable to update local ref)
I was able to work with
git remote update --prune
$ rm .git/refs/remotes/origin/master
$ git fetch
From bitbucket.org:xx/mkyong-tutorials
df0eee8..3f7af90 master -> origin/master
$ git pull
Already up to date.
Error: cannot lock ref" simply means information in /refs are corrupted and Git cannot continue to create index.lock file.
Quick fix : Remove and re-add remote.
1- Copy the SSH git URL of your existing remote. You can print it to the terminal using this command:
git remote -v
2- Remove the remote from your local git repo:
git remote rm origin
3- Add the remote back to your local repo:
git remote add origin git#server-address.org:your-username/repo-name.git
4- Prune remote origin
Users across online forums have reported that the command below worked for them:
git remote prune origin
5- Clean up and optimize local repository
git gc --prune=now
You can find more info on this article:
https://linuxpip.org/git-error-cannot-lock-ref/
delete file for particular branch manually from your project
.git/refs/remotes/origin/master
git gc --prune=now
git pull
For me, I had a local branch named feature/phase2 and the remote branch was named feature/phase2/data-model. The naming conflict was the cause of the problem, so I deleted my local branch (you could rename it if it had anything you needed to keep)
If git gc --prune=now dosen't help you. (bad luck like me)
What I did is remove the project in local, and re clone the whole project again.
I'm using Tower and for some reason my folder name was .git/refs/remotes/origin/Github. Changing it to lowercase .git/refs/remotes/origin/github solved the issue.
When it is caused by Google Drive desktop.ini files
Google Drive client for Windows creates desktop.ini files in each folder. If your git repository is in a directory that is being synced with Google Drive, then the desktop.ini files will cause the git repository to fail with something like:
cannot lock ref 'refs/remotes/origin/desktop.ini': unable to resolve reference 'refs/remotes/origin/desktop.ini': reference broken
To solve this error you might want to delete the desktop.ini files in your git repository.
If you have WSL setup, then you can use the following command to delete the desktop.ini files:
Note: ⚠️ This command will delete all desktop.ini files in all .git directories in your <project_directory>.
find <project_directory> -type d -name .git -print0 | xargs -0 -I {} find {} -type f -name desktop.ini -print0 | xargs -0 -I {} rm -vf {}
If you just want to delete the desktop.ini files in a specific .git directory, then you can use the following command:
find <.git_directory> -type f -name desktop.ini -print0 | xargs -0 -I {} rm -vf {}
Tried these but didn't work for me:
$ git gc --prune=now
$ git remote prune origin
$ git fetch --prune
I had to get this fixed by deleting the local folder and cloning again.
I had same issue. i follow following steps
1)switch your branch which having issue to other branch
2) delete that branch
3) checkout again.
Note:- You can stash you uncommitted changes and put it back again.
Got this issue when trying to clone from a git bundle created file, none of the other answers worked because I couldn't clone the repo (so git gc and removing/editing files was out of the question).
There was however another way to fix this - the source file of a .bundle file was begining with:
# v2 git bundle
9a3184e2f983ba13cc7f40a820df8dd8cf20b54d HEAD
9a3184e2f983ba13cc7f40a820df8dd8cf20b54d refs/heads/master
9a3184e2f983ba13cc7f40a820df8dd8cf20b54d refs/heads/master
PACK.......p..x...Kj.0...: (and so on...)
Simply removing the fourth line with vim fixed the issue.
I used git prune origin and that did the work.
Writing down a specific case that might cause this problem.
One day I pushed a branch named "feature/subfeature", while having "feature" branch on remote.
That operation worked fine without any error on my side, but when my co-workers fetched and/or pulled any branch, they all had the exact same error message unable to update local ref, cannot lock ref 'refs/remotes/origin/feature/subfeature.
This was solved by deleting feature branch on remote(git push --delete origin feature) and then running git remote prune origin on my co-workers' repo, which generated messages including * [pruned] origin/feature.
So, my guess is git fetch was trying to create subfeature ref in feature folder on git internally(.git/...), but creating folder failed because there was feature ref already.
Try this: git branch --unset-upstream
I was facing the problem earlier but I just solved it when I saw this command on the terminal.
# remove the reference file of the branch "lost"
rm -fv ./.git/refs/remotes/origin/feature/v1.6.9-api-token-bot-reader
# git clear everything
clear ; git reset HEAD --hard ; git clean -xdf ;
# subdue the current branch and pull all changes from the remote
clear ; git fetch --all -p ; git pull --all --rebase ; clear ; git branch -a
# git will "know" how-to handle the issue from now on
# From github.com:futurice/senzoit-www-server
# * [new branch] feature/v1.6.9-api-token-bot-reader ->
# origin/feature/v1.6.9-api-token-bot-reader
# and push your local changes
git push

BitBucket - error: failed to push some refs

I have some projects I would like to upload on my bitbucket private profile. I performed the following steps but I get an error.
Convert my project to git with: git init
Next:
git add
git commit -m "some message"
I created a bitbucket repository and version control system is GIT.
I then type this (of course with real account name and reponame and repo owner):
git remote add origin https://<repo_owner>#bitbucket.org/<accountname>/<reponame>.git
Finally,
git push -u origin master
I did all of this and my terminal gives me this error:
To https://bitbucket.org/milosdev_me/lfs.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'https://milosdev_me#bitbucket.org/milosdev_me/lfs.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
Try:
git push origin master --force
This works for me.
Your master branch has some code that you don't locally have, and to prevent you from conflicts, it doesn't let you to push further changes, before you have them locally. To resolve this, pull all the changes to your local repository (your project):
git pull origin master --allow-unrelated-histories
After that, you will have all the code that is available on your master branch.
NOTE: Be careful, pulling the code from remote branch might mess up all the changes locally. Make sure to save those changes somewhere, or create another branch locally where you will pull your origin master branch, so it doesn't mess up your changes.
Your issue is that you have different things between your local repository and your git repository (probably a readme file that you created automatically), so you have two options:
use git pull origin master, with this command, you will pull from your git repository, but it will cause a merge conflict, which you have to resolve using an IDE (recommended to beginners) or through cmd.
use git push origin master --force, this way, you will force your push from your local repository to your git repository, ignoring any merge conflict by overwriting data. I'm not sure, but I think it will overwrite all git repository data with you local repository data (which is what you want).
Adding --force option is a bad idea
Either rebase it or pull the code, merge it and push it.
git pull --rebase origin master
git push -u origin master
Your remote repository and local repository have differences, something new in remote repository. So for pushing you need pull changes, from remote, previously. Try do:
git pull
git push -u origin master
The issue is because your remote repository and local repository have differences.I had same issue and i tried all the above mentioned solution but nothing worked for me.
For me the scenario was :- I already had my branch in remote repository.If you have the same scenario then follow below steps:-
run command 'git pull'
delete branch from local repository
checkout that particular branch using "checkout as a new local branch" from
the Remote repository.
run command 'git branch -u <your_branch_name>'
run command 'git push or git push --force'
or you can try directly from step 4 first , if it does not work then follow entire steps.Hopefully it will help someone.
If you have your bitbucket account linked to jira.
(this answer will work for you, only if you have your jira account linked to bitbucket)
I was having the same problem trying to push my current branch with the origin.
for example:
my branch name was:
feature/PREFIX-000-new-name-branch.
previous commit:
git commit -m "Write your commit here"
so far it was not working.
you have to mentioned the ticket name in the commit.
if you have made the commit, make an --amend to rename your commit and retry it.
git commit --amend -m "PREFIX-000 Write your commit here"
try the push again.
If you are using BitBucket, this issue occured when I tried to push to a branch but that branch has writing disabled via the repository settings.
if you have already created a project locally and you want to upload it to git,
you will then need to do:
git status to see the changes you need to upload
git add . to add those changes to your repo
git commit -m "" to add a commit message
git push origin master
that way I solved the very same problem I
was having.
it might be a configuration issue
I fixed this issue after updating the global user.email value with my email
git config --global user.email my#email.com
Note: You need to delete the previous commit because it had the wrong email in the commit

Unable to update my GitHub from my Mac

Why am I unable to update my GitHub from my Mac?
git status produces the following:
On branch master Changes to be committed: (use "git reset HEAD
<file>..." to unstage)
new file: file.test
Untracked files: (use "git add <file>..." to include in what will be
committed)
.DS_Store
git push produces the following;
fatal: The current branch master has no upstream branch. To push the
current branch and set the remote as upstream, use
git push --set-upstream origin master
You need to git add ., then git commit -m "My commit message", then git push -u origin master.
That will set the upstream to the origin/master. Moving forward, just git push shall suffice
Git works through commits - which are basically snapshots of what your repository looked like at a given point in time. You need to commit the files to your repository before you can actually push them to GitHub.
So your first step is to add the files to the "Staging Area" with
git add file.text # you can do git add . but this will add all files which you may not always want
Now you can check the current status of the "Staging Area" with
git status
This will let you make sure that you are only committing the changes that you want added.
Now you can commit the changes. Committing will only 'save' the files that are in the Staging Area.
git commit -m "A useful description of what you did since your last commit"
Ok so now you're ready to push. Assuming you cloned from GitHub you can just run
git push origin master
But if you created this repository with git init you will need to tell git that you have a remote repository somewhere. Do this by running
git remote add https://github.com/<usernane>/<repo_name> origin
This origin is the name you would like to associate with the remote repository. 'Origin" is the most common but you may have other remotes like "backup" or "code_review" for different use cases.
Once you have added the remote repo, you can actually push to it with
git push origin master
Again, origin is the name for your remote repo and 'master' is a 'branch' name.
You can add the -u flag which will make it so that git assumes you want to push to origin. So in the future you would only need to run
git push
Listen to the error messages. :)
You currently have one untracked file, .DS_Store which I happen to know is a system file, so you may want to add that to your .gitignore
As for trying to push upstream, you need to set your upstream for each branch, so you simply need to type the command
$ git push --set-upstream origin master
then do a simple
$ git push
to send your changes to github.
If the branch you are pushing to online is ahead of you, then you may need to do a git pull to get grab the changes, before you do a git push.

Octopress pushing error to GitHub

I'm trying to push an octopress to github page,everything has worked fine up to now but when i do the rake deploy command after displaying octopress files i get the following error
To git#github.com:rukshn/rukshn.github.io.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'git#github.com:rukshn/rukshn.github.io.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Merge the remote changes (e.g. 'git pull')
hint: before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
what's the problem?
Since this is the master branch, i.e., the one running your generated pages, you need to drop into the _deploy directory, then do the git pull origin master. Somehow your deploy directory has gotten out of sync. Do you have more than one local repo you write to and deploy from? (Say on different machines...) If you do, then you should always make sure to sync your the sources on the various repos as well.
do
cd _deploy
git reset --hard origin/master
cd ..
and try again
rake generate
rake deploy
Try:
git checkout source
rake gen_deploy
#slavik comment works like a charm.
#Benjamin I think #rksh skipped below steps,
Don't forget to commit the source for your blog.
git add .
git commit -m 'add source code to source branch'
git push origin source
I met the problem and solved it by removing the master branch in the _deploy folder in the source branch. The detailed commands are as follows:
// change directory to _deploy
cd _deploy
// check out local master branch
git checkout master
// rename local master to master2
git branch -m master2
// list of remote branch
git branch -r
// create a new local master branch and tracking remote master branch
git checkout origin/master -b master
// pull the remote master branch, ensure that the local master branch has Already up-to-date.
git pull
// delete the local master2 branch if not needed.
git branch -d master2
```

Resources