How to merge branches with different case on windows in GIT? - windows

My colleague created by accident a branch named develop-client (lower case 'c') from our main branch "develop-Client" (upper case 'C'). We all work on windows. Now, how I can merge the develop-client back into develop-Client? Git in windows sees both branches as one, so when I try do "git merge --no-ff origin/develop-client" (when I am on develop-Client), it says "Already up-to-date".

Determine its SHA using command git rev-parse Branch_name and
merge using command
git merge SHA1

Either specify the hash of the HEAD commit of the branch you want to merge, or alternatively, manually rename the offending branch to a temporary name inside the .git/refs/heads directory.

This happened to me on my local repository. It was one commit ahead of remote. I simply renamed the files as Michael suggested:
In
.git/refs/heads/<in-lower-case>
to
.git/refs/heads/<in-Capital-case>
As I had also accidentally pushed to remote, I deleted the upstream lower case branch (at Github in my case) and in my local repo, changed remotes:
.git/refs/remotes/origin/<in-lower-case>
to
.git/refs/remotes/origin/<in-Capital-case>

Related

GIT : How to get latest changes from master branch to the custom branch using git commands?

Branch "abcd/child" is created from "abcd/master" . Changes are made to "abcd/child" and meanwhile "abcd/master" also have added changes. Now how to make sure the latest changes are pulled from "abcd/master" is available in "abcd/child" using git commands in git bash?
Assuming abcd is the name of your remote, here's how I'd do it:
git checkout child
git pull
git merge abcd/master
git push
When you checkout child, it'll probably say "set up to track remote abcd" or similar.
The git pull command does two things: It fetches all updates from the server (on all branches) to your local git repo, and it updates your branch to match what's on the remote.
The git merge abcd\master means to specifically bring in all of the commits that are on the remote's copy of the master branch. That's important because you may not have updated your local master to have all those commits.
Note also that you might get conflicts in the git merge if both abcd and master have edited the same sections of the same file. There's lots of help in resolving git merge conflicts.
Also: You want to make sure everything works after the merge. It's possible that the changes on master broke an API that you were using, so you may need to make edits to deal with that.
Update: My assumption about abcd being the name of the remote is wrong.
First, get the name of your remote with the git remote command. Mine goes like this.
git remote
origin
So I only have one remote, and I call it origin. That's pretty common. If you've got more than one remote, it'll be trickier.
So, with "origin" as the remote it goes like this:
git checkout abcd/child
git pull
git merge origin/abcd/master
git push
Obviously substitute the name of your remote if it's not origin.
Same caveats apply about conflicts and making sure it works.

how to reset a git working tree to an updated commitish

I need to extend a given tool with a Bash script that is supposed to work with Linux and MacOS. The script gets 2 parameters:
A repository location (file system, ssh, http(s), ...)
A commitish, e.g. branch, tag, commit hash
I have no influence on the parameters
The result of the script's run should be that
the repository is cloned to a fixed destination (always the same for one repository)
the repositorie's working tree should correspond to the latest state of the comittish (e.g. if it was a branch the tip of that branch)
If the repository does not (yet) exist locally, the procedure is as simple as
git clone $REPO_SOURCE $REPO_DIR
cd $REPO_DIR
git checkout $REPO_REF
My question: Consider a repository is already cloned to /repos/foo. After an obvios git fetch, how to I update that repository to the provided $REPO_REF?
If $REPO_REF was a branch, a git checkout $REPO_REF && git pull should work
If it was a commit hash, there was no update needed (just git checkout $REPO_REF?)
If it was a tag, then the tag might have been moved on the origin, how to handle this?
How to handle other edge cases?
Is there a simple reset-repository-to-this-commitsh way, so the repository behaves just as if it was freshly cloned?
Side nodes:
The same repository might be used with different commitish's, but only sequentially: It is guaranteed that the script isn't invoked more than once at the same time
All external changes to the repository might be always discarded without notification
While deleting and cloning the repository would work, it is impractical due to their sizes and it being an ugly solution
No (git) changes are needed, so checking out a detached head is okay
The only totally-foolproof yet convenient way is to have the other Git (the one you might be cloning, but might not) resolve the name for you. Then you have a hash ID and a hash ID is universal.
If the name is a branch or tag name, you can use git ls-remote to achieve that step. If it might be some other formulation (e.g., master~13) you're out of luck here. So, if you need to resolve the name locally:
If tag discipline is obeyed, no tag will ever move. This means that if you have an existing clone that has the tag, it has the right tag, and you're OK here, and if you have an existing clone that doesn't have the tag, you can add the tag and resolve it.
If tag discipline is not obeyed, you'd have to delete and re-create the tags (yuck), or else re-invent remote tags: copy their refs/tags/* names to your refs/rtags/<remote>/* name-space. See Git - Checkout a remote tag when two remotes have the same tag name.
If you have a branch name or something relative to a branch name, turn the branch name into your own remote-tracking name (e.g., replace master~13 with refs/remotes/origin/master~13) and resolve it.
In any case, you now have a hash ID and can use detached HEAD mode.
Using a "standard" git clone you could to this:
# cleanup old cruft
git reset --hard HEAD
git clean -fdx
# detach from current branch (if on any)
git checkout --detach
# delete all local branches
git for-each-ref --format="%(refname:strip=2)" refs/heads |xargs -r git branch -D
# fetch and update all remote refs and tags
git fetch --force --all --tags --prune --prune-tags
# checkout
git checkout "$COMMITISH"
That way you can rely on git checkout to do its job as usual and you don't need to replicate any of its heuristics, shortcuts etc.

Git checkout fails on untracked working tree files after git mv

I have a problem with my local branches. When I am trying to do git checkout <branch> I get this error message:
error: The following untracked working tree files would be overwritten by checkout:
... (list of files)
Please move or remove them before you switch branches.
Aborting
I think that the reason is a fact, that in current branch I've renamed/moved some files with git mv.
All the files listed in this error message are listed with old path (i.e. path before moving / renaming action). Is there any way to work around this problem? I'd like to move to my master branch now, and merge it with current branch, so after that there should be no problem, yet for now, I don't know how to successfully switch branches (and then do a merge, if there might again be some problems).
Edit:
I was able to checkout using -f option, but the problem remains, because now I can't do merge, for the same reasons (actually, now the paths are the opposite, i.e. now error message contains new paths, that were used in database branch) and I don't know an option to force git to do this merging.
I am not sure, but probably the same solution would work for both checkout and merge problem.
Following #LutzBüch comment, I am trying to show exactly what happened in this repo.
I have branches master and database. The database branch worked only on a parts strictly related to database only. This part of code remained in a directory named let's say db. At some point, I had to change this dir name to DB, so I did some git mv's. Let's follow it from last merge, when everything still worked.
git checkout master
git merge database
git checkout database
git commit
{now the renaming happens}
git mv db/. tmp/.
git mv tmp/. DB/.
git commit {no other changes were made}
{added some renaming related changes, i.e. changed paths in 2 files}
git commit --amend
{now it's becoming the standard}
git commit {multiple times}
git checkout master {fails}
Last command failed with error message mentioned earlier. All files on the list had paths with the old dirname, i.e. db. After using git checkout -f master, when I tried to do merge I received paths with DB as the dirname.

Git missing branch name on remote

I have following situation, github is my origin, and I see there is branch with name Release1.0. I see it also in my console:
xyz#yxz MINGW64 /c/myreponame (Development)
$ git remote show origin
* remote origin
Fetch URL: https://github.com/myorganization/myreponame
Push URL: https://github.com/myorganization/myreponame
HEAD branch: Development
Remote branches:
Release1.0 tracked
Development tracked
But when I try to switch to that branch I see:
xyz#yxz MINGW64 /c/myreponame (Development)
$ git checkout --track Release1.0 origin/Release1.0
fatal: Missing branch name; try -b
I think important note, here Im using Windows, may it is some problem with upper case in branch name? Windows is case insensitive.
UPDATED to reflect an edge case that would mess with the checkout shortcut
This means that you haven't yet created the local branch Release1.0. The branch exists on the remote, and you have a tracking ref for it - that's what the show origin output is telling you.
But the checkout syntax you're using isn't correct for setting up the local branch to track the remote branch. Simply
git checkout Release1.0
will likely work. This is a special case "shortcut" built into the checkout command, because it's common to want to "copy" a branch from the one available remote. The cases where it won't work:
If there are multiple remotes with the same branch name, then git will not know which one to check out so will refuse to use the shortcut.
If you have a tag with the same name, git will check that out (in detached HEAD state) instead. In that case you can still create the branch (without the shortcut; see below), but beware of having a tag and a branch with the same name. (In practice git has fairly sensible rules for how any given command will behave, and you always can disambiguate between the tag and the branch; but it's better not to have to think about such things.)
The other way, besides the shortcut, to create the branch: you can use the -b option (as the error message indicates), as that's the more general way to create a branch during a checkout operation. Or you can use git branch.
Unless there's more going on than you've spelled out, this is not a windows / case sensitivity issue. Note that saying "Windows is case insensitive" is not meaningful. It is correct that Windows typically uses file system with case-insensitive filenames, and this would cause problems if you tried to create two branches whose names are identical except for case. But nothing says that branch names have to be all-lowercase (which would actually be a peculiar form of case-sensitivity).

git branch created from windows not seen on gitbash window

I created a new branch from my windows command box from the devdesktop application. but when I got to git bash and try to find this branch it doesn't exist. What can I do to sync what I see in git bash with what I created?
Choose one of below commands:
(1) Display latest branch with timestamp:
git for-each-ref --sort='-authordate:iso8601' --format=' %(authordate:relative)%09%(refname:short)' refs/heads
(2) List all branches at remote and local:
git branch
(3) List all branches, order by commit time desc, you will see lasted touched branch:
git branch --sort=-committerdate
(If order in ASC, git branch --sort=committerdate)
I was in another repository which had the same directory structure but was on a separate drive.

Resources