I'm working on some CI automation involving pushing to a git branch, using git on Windows (Git 2.34.1).
My problem is whenever I push to my upstream branch, and the push fails because since starting my CI job, that branch has been updated by something else, and so I need to rebase.
I run git pull --rebase -Xtheirs, yet the pull command fails, and I see lots of these errors, for every branch in the repository (i've just included a couple here, because we have hundreds of branches):
error: cannot lock ref 'refs/remotes/origin/custom-branch/test?': Unable to create 'C:/r/w/cover/CF/SpringProject/.git/refs/remotes/origin/custom-branch/test?.lock': Invalid argument
error: could not remove reference refs/remotes/origin/custom-branch/test?
error: cannot lock ref 'refs/remotes/origin/custom-branch?': Unable to create 'C:/r/w/cover/CF/SpringProject/.git/refs/remotes/origin/custom-branch?.lock': Invalid argument
error: could not remove reference refs/remotes/origin/custom-branch?
To me, it looks like it's trying to create a branchname?.lock file for every branch, yet because ? is an invalid character in Windows, it's unable to do this and thus doesn't get anywhere.
Have people seen anything this before? I've upgraded from Windows Server 2019 to Windows Server 2022, but I don't see how that could make any difference to this?
Related
I'm trying to clone a repo to my computer. I do the standard
git clone [link to bitbucket repo]
and then call
git branch -a
to see my remote branches, which shows
remotes/origin/develop
which is the branch I want to checkout into. However, when I type
git checkout develop
I get an error that says
error: invalid path '.\api-log\api.log'
and it fails to create the local develop branch. Is this happening because there is something wrong with the file? If so, how can I fix/remove the file so that the clone will go through? All the work is in the develop branch and nothing in the master.
I'm using Windows.
Apologies if this has been answered before but I couldn't find anything.
I don't know exactly why this happen but I suggest you to remove the offending file from the repository history by the wonderful BFG tool.
At this url https://rtyley.github.io/bfg-repo-cleaner/ you can get the software and the documentation.
I use Git on Windows 10 to track version control for projects I keep on my company's shared network drive. I have a project for which I have been using Git for months with no trouble. I recently created a new branch 'development' and have been using it as a testing environment for new changes before merging the changes back to master. This arrangement has been working fine for the last few commits until now.
I made changes in the testing branch then went to commit my changes but received the below error:
$ git commit -m "this is a commit description"
fatal: cannot update the ref 'HEAD': unable to append to '.git/logs/HEAD': Bad file descriptor
I now notice this error with many different operations, including git checkout <branch>. The error in this case is:
$ git checkout branch-name
error: unable to append to '.git/logs/HEAD': Bad file descriptor
I'm relatively new to this stuff so apologies if there is an obvious solution here. Any help is appreciated!.
The Bad file descriptor error is coming from your operating system. In C programs (which this particular Git program is), to write to a file, the program is required to first open the file, which produces a file descriptor: a number, usually a small integer such as 3 or 4. Then, to write to that file, the program should make an OS call of the form write(fd, data, len) where fd is an int variable holding the number returned earlier by open.
The Bad file descriptor error means that the number being passed to write is incorrect in some way: perhaps it is out of range or was never returned by an open call, or perhaps it refers to a file that is open, but not for writing. In general, if there are no programming mistakes, this should not happen.
You did, however, mention a shared drive. On Unix-like operating systems, when using networks to access files, things can go wrong that simply cannot happen if the drive is local.1 On these Unix-like systems you would normally get an ESTALE error ("Stale network file handle") rather than an EBADF ("Bad file descriptor") error here, but perhaps this is what is going wrong. In general it's unwise to attempt to use Git across any sort of sharing system: Git really wants full and total control over everything it does, and putting it on any kind of shared system—network drives, Dropbox, OneDrive, Google Drive, etc.—tends to be a bad idea.
This arrangement has been working fine for the last few commits until now.
This behavior is highly characteristic of attempts to use shared file systems with Git: it works great, until it doesn't. If you're lucky, the "doesn't" is merely a minor malfunction like this; if not, it wrecks the entire repository, and since you've been relying on the sharing instead of making clones, there may not be any backup clones from which to fix things.
1Technically, similar things can go wrong, if, e.g., the drive catches on fire. But usually by then the program has stopped running for other reasons. 😅
I was able to resolve this issue by performing the below actions:
Create a local desktop directory
$ cd '<local-directory>'
Clone the repo into this directory
$ git clone '<origin-directory>' .
Make and commit the backlogged changes
$ git commit -m "commit desc"
Break link to remote origin source
$ git remote remove origin
Delete everything in original directory
Copy the contents of the local directory back to the original directory
It seems to work for now but if this happens again I'll just repeat these steps.
I had an issue where I accidentally copied a directory into a subdirectory of itself thus creating thousands of git transactions. After unsuccessfully trying to clean that up, I decided to create a new project and copy the files over from the old one. Somehow I think I've messed git up, but I'm not sure where the problem is. Here are my current symptoms.
I thought I initialized the git repository correctly. However, none of the files exist on github.
https://github.com/victorengel/matchismo2
... except what I created there.
The project itself is an iOS single view application that I created with git enabled. I copied over all the files I needed from the old project to the new project area, confirmed that it ran, and then tried a commit. The commit seemed to work, but the push didn't.
If I tried a push, I got a message that the working copy is out of date and that I should do a pull. If I tried a pull, it said there were uncommitted changes and I should abandon them or commit them. After some rooting around, I figured out that the change triggering this was a user data change that should have been ignored in .gitignore.
I finally have the .gitignore set up the way it needs to be. I think the repository is set up right on github.com, but I'm still getting errors.
I can commit but not push. If I try to push I get the message "Working copy out of date. Try pulling from the remote to get the latest changes, then push again."
If I try a pull, I get the message "matchismo2/master" is not a valid remote branch to pull from. Please choose a different remote branch.
Looking around at github.com, there is only one branch, master under victorengel/matchismo2. To me it looks like everything is set up properly, but apparently I'm missing something. What is it?
In Xcode, in the organizer, if I click on Branches, there is one item listed: master.
If I click on Remotes, there is one item, matchismo2, and if I expand it, master is listed.
I've been assuming this matchismo2 with master underneath it is what is supposed to match the "matchismo2/master" that's in the error message. Looks like a match to me, so why isn't it working?
EDIT:
If I try pulling from the GitHub application, I get an error message "There aren't any remote branches on the server yet." If I try publishing from GitHub, I get the following:
git: 'credential-osxkeychain' is not a git command. See 'git --help'.
2013-03-05 16:32:43.680 GitHub for Mac Login[68518:707] AskPass with arguments: (
"/Users/brillig/Downloads/GitHub.app/Contents/MacOS/GitHub for Mac Login",
"Password for 'https://victorengel#github.com': "
)
2013-03-05 16:32:43.763 GitHub for Mac Login[68518:707] Error reading attributes: OSStatus -2033889429
2013-03-05 16:32:43.764 GitHub for Mac Login[68518:707] Error reading attributes: OSStatus -2033889429
2013-03-05 16:32:43.919 GitHub for Mac Login[68518:707] Error reading attributes for password: OSStatus 840183217
git: 'credential-osxkeychain' is not a git command. See 'git --help'.
To https://victorengel#github.com/victorengel/matchismo2.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://victorengel#github.com/victorengel/matchismo2.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.
(256)
How about ensuring all your files are in order, renaming your branch, and pushing to the new (renamed branch) ? Then once you determine everything you need is actually there and your new code works, you can force update the master. Not an ideal way to do it, but it might work for you.
Recently I started getting this error everytime I commit to my local Xcode git.
fatal: Not a git repository (or any parent up to mount point /Volumes/xxx)
Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).
I have partitioned my HDD into 2 drives and my source code is on one of them. All my source is local and I'm just using the built in Git with Xcode. Any clues why I get this error?
Check this. You must be missing git init. This is the first command to start with. This command creates an empty Git repository - basically a .git directory
Using Windows 7, we have a bare GIT repository set up on a network drive so that multiple users can pull/push from it. I am able to create a new working repo on my local and multiple other networked drives. However, when I try to clone a new working repository on the same network drive (different folder) , it fails.
Using TortoiseGIT, after I right-click and choose "GIT Clone", put in all of the necessary paths to my bare repo (the new working repo is already filled in) and hit ok, I get the following error:
Cloning into 'R:\path\to\new\repo'... done.
error: refs/remotes/origin/master does not point to a valid object!
error: Trying to write ref refs/heads/master with nonexistent object 5d2164db2c61efc7a5598f6ff75ed3fbbb12456e
fatal: Cannot update the ref 'HEAD'.
fatal: The remote end hung up unexpectedly git did not exit cleanly (exit code 128)
and it fails to create the repo. It does however build the new folder & ".git" subfolder structure.
It's not a r/w permissions issue because I can r/w any other files, but just cannot seem to create this newly cloned repo. My co-worker cannot either. Even if I got to another folder on the network drive, I still cannot clone the repo successfully. Surprisingly, if I just copy/paste a repo I created in another location, then manually do a "pull", it works and updates successfully.
Any ideas on what to try next? Obviously I've Googled "exit code 128" and "cannot update the ref 'HEAD'" but cannot find a solution to my issue. It's probably something really simple that we are overlooking, but we're just getting started with GIT and this is really causing us headaches...
UPDATE: I just noticed that when I do a manual pull from GIT to my "copy", it is doing a Fast-Forward. Maybe this provides some additional clues?
From R:/path/to/repo
* branch master -> FETCH_HEAD
Updating 5d2164d..d75bdb7
Fast-forward
Files.py | 3 +++
1 file changed, 3 insertions(+)
Success
Git might be trying to do some smart stuff with hardlinks that fails on the network drive. Try using git clone --no-hardlinks /r/path/to/my/repo or git clone file:///r/path/to/my/repo
Please do this via command line in msysgit
git clone /r/path/to/my/repo /r/some/other/path
Further, I would recommend using git from the command line as it is a tool that was designed to be used from the command line. You will be able to find more help, faster, with any issues that come up for you.