1

I have two branches one for developing and other for staging. I first checkout the developing branch and then build some files on it and then checkouts staging branch and push the new files to staging

git checkout develop
#
# Run some build scripts here
#
git fetch origin staging:staging
git checkout staging
git add *
git commit -m "new commits"

but its giving this error

error: Untracked working tree file * would be overwritten by checkout.
                            file.1
                            file.2
                            file.3

file.1 and file.2 and file.3 doesn't exist in develop branch but it creates after the build script runs and it also exists in staging.

I tried multiple ways to solve this problem. I tried force checking out git checkout --force staging but it exits with nothing to update message. Then I tried this

git fetch origin staging:staging
git stash
git reset --hard
git checkout staging
git add --all
git commit -m "new commits"

which also fails

ERROR

Auto-merging newfile.xx
CONFLICT (add/add): Merge conflict in newfile.xx
On branch staging
Unmerged paths:
  (use "git restore --staged <file>..." to unstage)
  (use "git add <file>..." to mark resolution)
    both added:      newfile.xx
torek
  • 448,244
  • 59
  • 642
  • 775
Eka
  • 14,170
  • 38
  • 128
  • 212
  • 1
    Try this: https://stackoverflow.com/a/12323348/7976758 (add, *no commit*, stash push, checkout, stash pop): `git add file.* && git stash && git checkout staging && git stash pop` – phd Nov 06 '22 at 20:27
  • It partially worked but I am getting error in one file `newfile.xx` – Eka Nov 07 '22 at 01:05
  • I recommend `git worktree`, by which you can checkout each branch into separate directories while they share the same `.git`. – ElpieKay Nov 07 '22 at 01:16
  • I doubt that you really mean `git add *`. – matt Nov 07 '22 at 01:20
  • @Eka: the second sequence of commands you mention will not create a merge conflict. Did you forget to post one of your git commands ? like `git stash pop` or `git merge develop` ? – LeGEC Nov 07 '22 at 06:34

0 Answers0