1008

So I added a folder to my .gitignore file.

Once I do a git status it tells me

# On branch latest
nothing to commit (working directory clean)

However, when I try to change branches I get the following:

My-MacBook-Pro:webapp marcamillion$ git checkout develop
error: The following untracked working tree files would be overwritten by checkout:
    public/system/images/9/thumb/red-stripe.jpg
    public/system/images/9/original/red-stripe.jpg
    public/system/images/8/thumb/red-stripe-red.jpg
    public/system/images/8/original/red-stripe-red.jpg
    public/system/images/8/original/00-louis_c.k.-chewed_up-cover-2008.jpg
    public/system/images/7/thumb/red-stripe-dark.jpg
    public/system/images/7/original/red-stripe-dark.jpg
    public/system/images/7/original/DSC07833.JPG
    public/system/images/6/thumb/red-stripe-bw.jpg
    public/system/images/6/original/website-logo.png
    public/system/images/6/original/red-stripe-bw.jpg
    public/system/images/5/thumb/Guy_Waving_Jamaican_Flag.jpg
    public/system/images/5/original/logocompv-colored-squares-100px.png
    public/system/images/5/original/Guy_Waving_Jamaican_Flag.jpg
    public/system/images/4/thumb/DSC_0001.JPG
    public/system/images/4/original/logo.png
    public/system/images/4/original/DSC_0001.JPG
    public/system/images/4/original/2-up.jpg
    public/system/images/3/thumb/logo2.gif
    public/system/images/3/original/logo2.gif
    public/system/images/3/original/Guy_Waving_Jamaican_Flag.jpg
    public/system/images/3/original/11002000962.jpg
    public/system/images/2/thumb/Profile Pic.jpg
    public/system/images/2/original/Profile Pic.jpg
    public/system/images/2/original/02 Login Screen.jpg
    public/system/images/1/original/Argentina-2010-World-Cup.jpg
Please move or remove them before you can switch branches.
Aborting

This is what my .gitignore file looks like:

.bundle
.DS_Store
db/*.sqlite3
log/*.log
tmp/**/*
public/system/images/*
public/system/avatars/*

How do I get this working so I can switch branches without deleting those files?

If I make a change, will it affect those files? In other words, if I came back to this branch afterwards would everything be perfect as up to my latest commit?

I don't want to lose those files, I just don't want them tracked.

Pavan Nagadiya
  • 652
  • 4
  • 10
marcamillion
  • 32,933
  • 55
  • 189
  • 380
  • 50
    if you really don't care about these files: git checkout -f in My case the files are generated in the build process, so I coudln't care less – Hobbamok Sep 21 '18 at 11:29
  • Sometimes happens if you do 'git checkout' (without a branch name). To fix, do 'git checkout branchname' – crafter Nov 05 '18 at 14:32
  • 2
    Separate, but critically related question: why does this error occur at all? why can't git just switch between branches? – ahnbizcad Dec 08 '18 at 01:55
  • 2
    @ahnbizcad Because if you were working on a new file, and someone on another branch happened to commit a file with the same name, you would be pissed off if git trashed your version when you switched branches. That's why the -f flag is there. – Matthew Sharp Jul 30 '19 at 01:12

33 Answers33

1205

WARNING: it will delete untracked files, so it's not a great answer to the question being posed.

I hit this message as well. In my case, I didn't want to keep the files, so this worked for me:

git 2.11 and newer

git clean  -d  -f .

older git

git clean  -d  -f ""

If you also want to remove files ignored by git, then execute the following command.

BE WARNED!!! THIS MOST PROBABLY DESTROYS YOUR PROJECT, USE ONLY IF YOU KNOW 100% WHAT YOU ARE DOING

git 2.11 and newer

git clean  -d  -fx .

older git

git clean  -d  -fx ""

http://www.kernel.org/pub/software/scm/git/docs/git-clean.html

  • -x means ignored files are also removed as well as files unknown to git.

  • -d means remove untracked directories in addition to untracked files.

  • -f is required to force it to run.

Black
  • 18,150
  • 39
  • 158
  • 271
Scott Schafer
  • 12,451
  • 2
  • 13
  • 2
  • 146
    BE CAREFUL WHEN RUNNING git clean! – Noel May 01 '14 at 15:06
  • 263
    To avoid a facepalm, first run it with the dry-run option to see what it would do: `git clean -dfxn` or `git clean -dfx --dry-run` – Dennis Jun 26 '14 at 16:28
  • I think if you run `git ls-files --others --exclude-standard` and nothing is listed it's more generally safe to use this answer. For me, I had a lot of untracked .DS_Stores – JuJoDi Jul 15 '14 at 14:05
  • 3
    As others have said, be very careful when running this function as it will delete all files in your working directory that are untracked by Git (such as the 'shared' folder in a Capistrano project or a machine specific config file). Run ``git clean -dfxn`` first to see what files will be affected. *weeps softly* – Andrew Jul 18 '14 at 18:50
  • 4
    How can I undo this command? i deleted accidentialy some important files... :( – BvuRVKyUVlViVIc7 Jul 31 '14 at 11:25
  • X| ok I just run the command without reading the next phrase. this deleted all my configuration files (actually not a problem) – albanx Sep 22 '14 at 16:59
  • 79
    Holy crap. This deletes all the config files on my xcode and now the project is turning into mac project. BE VERY CAREFUL WHEN RUNNING THIS COMMAND. I thought it would only remove it from git. – tyegah123 Sep 29 '14 at 08:37
  • 27
    The `-x` option hurts me – wener Nov 12 '14 at 03:17
  • 2
    +1 - didn't even realise that half of my static media directory was cached by Git – scrowler Nov 19 '14 at 01:05
  • @Scott_Schafer thanks! I had these problem with cloned Ember.js github repository. Current tag was _v2.2.0_ and I couldn't checkout tag _v1.12.1_ which is version my SPA is based on. Thanks again! – Marecky Aug 27 '15 at 10:33
  • Except if delete untracked files is what you want. Thank and vote up – Diego Andrés Díaz Espinoza Jan 23 '16 at 18:07
  • 1
    Oh... right about now, I'm all into punishing my repo... effing git - just do what I want! Would be nice if it simply had a --force option to shut. It. Up. – Jon Feb 08 '16 at 21:30
  • 6
    This DELETED ALL MY LARAVEL VENDOR DIRECTORY. Please be very careful. – Jilson Thomas Feb 18 '16 at 16:07
  • @JilsonThomas It looks to remove files that are gitignored aswell (untracked) as it removed my node_modules , only in dry run though – Kiee May 05 '16 at 16:03
  • It will remove entire folder's content from local repository.after clean ,you can pull all content from remote repository. – BABU K May 13 '16 at 05:06
  • The cmd is virus.. Be careful .. -1 – Abdennour TOUMI Sep 13 '17 at 15:57
  • Help! Is it possible to undo this ? I'm on linux – zacurry Dec 20 '17 at 04:57
  • 3
    Someone can delete this answer ? – Walid Aug 21 '18 at 09:20
  • Worked for me, I was trying to revert files coming from a merge and it solved all my problems. Now I don't have a job. – Frederiko Ribeiro Oct 26 '19 at 00:03
  • Thank god GoLand tracked my local history for my folder. Like many others ran tis command foolishly in a blind panic. If you're in a similar situation, check your IDE's Local History if you're using a JetBrains IDE – howdoyouturnthison Dec 12 '19 at 20:01
  • 1
    This is the equivalent of using a nuke to kill a spider. -1 – Catsunami Aug 19 '20 at 14:29
789

Warning: This will delete the local files that are not indexed

Just force it : git checkout -f another-branch

aerin
  • 20,607
  • 28
  • 102
  • 140
Régis
  • 8,340
  • 1
  • 17
  • 15
286

It seems like you want the files ignored but they have already been commited. .gitignore has no effect on files that are already in the repo so they need to be removed with git rm --cached. The --cached will prevent it from having any effect on your working copy and it will just mark as removed the next time you commit. After the files are removed from the repo then the .gitignore will prevent them from being added again.

But you have another problem with your .gitignore, you are excessively using wildcards and its causing it to match less than you expect it to. Instead lets change the .gitignore and try this.

.bundle
.DS_Store
db/*.sqlite3
log/*.log
tmp/
public/system/images/
public/system/avatars/
Fry
  • 6,235
  • 8
  • 54
  • 93
Arrowmaster
  • 9,143
  • 2
  • 28
  • 25
  • 2
    Thanks....I removed all the files from the current branch and backed them up. Then switched branches and put them back. That worked. Also, thanks for the tip on the .gitignore though – marcamillion Feb 01 '11 at 02:36
  • @marcamillion: What do you mean by "that worked"? If the files were tracked on the branch you switched to, you've overwritten them with your versions, which could be different... – Cascabel Feb 01 '11 at 06:30
  • 1
    I was having an issue with a /build folder that doesn't need to be tracked. So I deleted the local folder, committed my .gitignore file, then checked out the other branch. That finally worked for me. – Mike S. Oct 12 '11 at 19:40
  • 19
    I think the first part is for the reverse of this particular error message. This error is stating the user is currently in a branch that doesn't have those JPG files tracked and the user is trying to move to one that does. So doing ```git rm --cached``` will not make a difference, those files don't exist in the current branch. For this error I think the user instead needs to follow @Greg Hewgill's answer - "move them out of working copy, switch branches, and move them back". – studgeek Jan 29 '13 at 22:20
  • That said, in this particular case his real problem may not be the error message, but his gitignore. Which you solve correctly in the 2nd part. He is ignoring files he does want to ignore. Once he removes them from the ignore his working directory will no longer be clean forcing him to deal with the JPGs (by committing or deleting them) before he switches branches. Just pointing out the difference since googling for the error message takes you to this question, but this top answer really for that error message. – studgeek Jan 29 '13 at 22:23
  • 6
    How would one go about solving the `your files would be overwritten` with `fatal: pathspec 'test/node_modules' did not match any files` when I do `git rm -r --cache test/node_modules`? I can't pull because of the overwritten message and can't remove because git can't find them (they are there) – HMR Feb 06 '15 at 07:40
  • In my case, I had committed a file that I later ignored. So, I temporarily moved it out of the project and moved it back after the merge was complete. Thanks. – aashah7 Jun 25 '17 at 18:37
  • I'm having exactly this problem because I used `git rm --cached myfiles.ext`. Now I can't switch branches without getting the OPs warning on all of `myfiles.ext`. I thought the point of `rm --cached` was that it doesn't delete the files from system, only tracking. – rocksNwaves Nov 11 '20 at 17:17
  • 1
    @rocksNwaves Does the branch you are trying to change to also have those files committed to it? If so and you do not want those files to be tracked in any branch, you should backup the files outside of the git repo first. Then you can switch to each branch and use `git rm` to delete the files in that branch and commit. Finally you can move the files back and they wont be overwritten anymore. – Arrowmaster Dec 20 '20 at 21:49
198

If you're on OS X, it may be because a file's name has had certain characters change case. Try setting the following config option:

git config core.ignorecase true
mattbasta
  • 13,492
  • 9
  • 47
  • 68
  • 16
    It worked on Windows as well, looks like this situation happened in the first place due to case change which GIT couldn't determine – SagiLow Jan 30 '15 at 13:08
  • 4
    This is exactly the problem I had, a file path was different by one letter case - Windows treats this as same but GIT does not which is the problem. – Daniel Sokolowski Aug 01 '15 at 03:19
  • 1
    My problem happened in checkout another branch in Windows 10, and only this work for me, Thanks – Weijie Sun Apr 11 '17 at 15:49
  • 3
    It works also if you try to `git rebase` as well. Thanks. – user3890355 Aug 09 '18 at 12:59
  • Awesome! Fix my problem! Been using Mac OS X for so many years, I'm astonished its file system is case insensitive... – Murphy Ng Mar 19 '19 at 06:29
  • Thanks. It helped. After changing one char to lowercase at filename at OSX (which filesystem is case insensitive by default), I had this issue until tried your solution. – igormukhingmailcom Nov 13 '20 at 02:30
  • This fixed it for me, I would also recommend setting it back to `false` once you fix this issue if your production filesystem is case-sensitive (linux) – IliasT Aug 09 '23 at 00:00
55

This worked for me.

 1. git fetch --all
 2. git reset --hard origin/{branch_name}
Ori Marko
  • 56,308
  • 23
  • 131
  • 233
  • 5
    Please add explanation on your solution. see https://stackoverflow.com/help/how-to-answer – Ori Marko Jan 08 '18 at 12:54
  • Here's my take. Your local copy of the remote branch actually has all of the untracked files, somehow. You're checking that out to restore the untracked files it originally complained about. Now you can switch to other branches – ahnbizcad Dec 08 '18 at 01:24
  • 3
    For some reason, this is the only working solution for me. Thanks mate. – JFC Jan 29 '19 at 04:04
  • Solved my problem. Thanks – Devashis Kant Mar 29 '19 at 12:02
  • Many thanks, so simple! git reset --soft origin/develop . How I hate these merge conflicts editing. This command so nice and simple. – Andrew Jun 09 '19 at 07:58
  • A folder had code same as git branch (it was manually copied). I just had to link this local folder to git branch. And your commands were useful. It didn't delete or overwrite anything. I still don't know why they worked but they did. Todo: Learn why :) – Jags Jun 01 '20 at 15:05
49

Git is telling you that it wants to create files (named public/system/images/9/... etc), but you already have existing files in that directory that aren't tracked by Git. Perhaps somebody else added those files to the Git repository, and this is the first time you have switched to that branch?

There's probably a reason why those files in your develop branch but not in your current branch. You may have to ask your collaborators why that is.

how do I get this working so I can switch branches without deleting those files?

You can't do it without making the files disappear somehow. You could rename public to my_public or something for now.

if I came back to this branch afterwards would everything be perfect as up to my latest commit?

If you commit your changes, Git won't lose them. If you don't commit your changes, then Git will try really hard not to overwrite work that you have done. That's what Git is warning you about in the first instance here (when you tried to switch branches).

Greg Hewgill
  • 951,095
  • 183
  • 1,149
  • 1,285
  • Thanks for the explanation. I backed up the files, switched branches and merged them then replaced the files in the public folder. That worked. – marcamillion Feb 01 '11 at 02:37
  • 2
    As I commented on @Arrowmaster's answer. This is the right answer for the error message. It may not be the right answer for this particularly questioner since he real problems seems to be his gitignore. – studgeek Jan 29 '13 at 22:27
23

There is a command for this delicate task (permanently deleting untracked files)

git clean -i

Then git pull will do.

Abhishek Goel
  • 18,785
  • 11
  • 87
  • 65
22

These two functions

  1. git rm --cached
  2. git checkout -f another-branch

did NOT work for me.

Instead, I physically removed the file (in eclipse) as what Git tells you to do;

Please move or remove them before you can switch branches.

and then I add/committed it.

and then I pulled and it worked!

Wolfson
  • 1,187
  • 17
  • 22
In-young Choung
  • 779
  • 2
  • 8
  • 22
15

For those who need something less far-reaching than Scott Schafer’s answer,

git clean -f

will likely work. I highly suggest running

git clean --dry-run

first. That command will output a list of files that Git will remove if you run git clean -f, and might save you the pain of inadvertently removing something you didn’t want to.

See this Stack Oveflow answer or the docs for more information on git clean.

Rory O'Kane
  • 29,210
  • 11
  • 96
  • 131
mc_kaiser
  • 717
  • 8
  • 18
12

Unfortunately neither git rm --cached or git clean -d -fx "" did it for me.

My solution ended up being pushing my branch to remote, cloning a new repo, then doing my merge in the new repo. Other people accessing the repo had to do the same.

Moral of the story: use a .gitignore file from inception.

Kyle Clegg
  • 38,547
  • 26
  • 130
  • 141
12

this commands solved my problem:

git add * 
git stash
git pull
saber tabatabaee yazdi
  • 4,404
  • 3
  • 42
  • 58
9

This happened to me on a Windows 8 system, using Git from the command prompt. The rest of my team uses TFS, and I use Microsoft's git-tf to push/pull between TFS and my local Git repository.

The problem arose due to some files that had been renamed only to change their case. What appears to have happened was this:

  • The files were checked in with mixed casing in their names.
  • In a later commit, the file names were changed to all lower-case.
  • git-tf initially got the files in mixed case.
  • When the files were renamed to lower-case, git-tf didn't get the files because to Windows 8 those file names are equivalent.
  • Since Git is case-sensitive, it complained that I had the mixed-case files that weren't in source control. But using git status, I couldn't see any changes, since in the Windows command prompt those file names are equivalent.

The simplest solution for me was:

  • git checkout a previous version of the project, well before those files were ever added.
  • Then git checkout the latest version of the project, with the correct file casing.
Ryan Lundy
  • 204,559
  • 37
  • 180
  • 211
  • +1 I was able to use git log on the current branch and branch to rebase to see when the commit occurred that changed the case; then I hacked around it... – sage Apr 10 '16 at 17:11
9

If you want to quickly resolve this question,You can use this command:

git checkout -f dev
Nakilon
  • 34,866
  • 14
  • 107
  • 142
GeekHades
  • 3,028
  • 3
  • 19
  • 15
9

I had the same problem when checking out to a branch based on an earlier commit. Git refused to checkout because of untracked files.

I've found a solution and I hope it will help you too.

Adding the affected directories to .gitignore and issuing $ git rm -r --cached on them is apparently not enough.

Assume you want to make a branch based on an earlier commit K to test some stuff and come back to the current version. I would do it in the following steps:

  1. Setup the untracked files: edit the .gitignore and apply $ git rm -r --cached on the files and directories you want the git to ignore. Add also the file .gitignore itself to .gitignoreand don't forget to issue $ git rm -r --cached .gitignore. This will ensure that the ignore behavior of git leaves the same in the earlier commits.

  2. Commit the changes you just made:

    $ git add -A
    $ git commit
    
  3. Save the current log, otherwise, you may get problems coming back to the current version

    $ git log > ../git.log

  4. Hard reset to the commit K

    $ git reset --hard version_k

  5. Create a branch based on the commit K

    $ git branch commit_k_branch

  6. Checkout into that branch

    $ git checkout commit_k_branch

  7. Do your stuff and commit it

  8. Checkout back into master again

    $ git checkout master

  9. Reset to the current Version again

    $ git reset current_version or $ git reset ORIG_HEAD

  10. Now you can reset hard to the HEAD

`git reset --hard HEAD`

NOTE! Do not skip the next-to-last step (like e. g. $ git reset --hard ORIG_HEAD ) otherwise, the untracked files git complained about above will get lost.

I also made sure the files git complained about were not deleted. I copied them to a text-file and issued the command $ for i in $(cat ../test.txt); do ls -ahl $i; done

If you checkout to the branch mentioned above again, do not forget to issue $ git status to ensure no unwanted changes appear.

Abdel
  • 69
  • 3
Juri Sinitson
  • 1,445
  • 1
  • 14
  • 18
5

In my case, the problem was with the submodules. master was merged with another branch which added a new submodule to the project. The branch I was trying to checkout didn't have it, that's why git was complaining about untracked files and none of the other suggested solutions worked for me. I forced the checkout to my new branch, and pulled master.

  • git checkout -f my_branch
  • git pull origin master
  • git submodule update --init
wisbucky
  • 33,218
  • 10
  • 150
  • 101
Bruno Pinheiro
  • 155
  • 1
  • 8
3

In my case git rm --cached didn't work. But i got it with a git rebase

Hillkorn
  • 633
  • 4
  • 12
3

I was also facing a similar issue and i tried all the solutions posted above but it didn't work

The issue was caused when i renamed my onMusicUpdateListener.java to OnMusicUpdateListener.java in develop branch.

Now master had onMusicUpdateListener.java and develop had the same file as OnMusicUpdateListener.java

Now whenever i switched to master it gave me an error

The following untracked working tree files would be overwritten by checkout

and then it aborted.

In order to solve this, i forcefully checked out master branch and then renamed my onMusicUpdateListener.java to OnMusicUpdateListener.java, committed it and then merged it with develop branch.

Then i updated my develop branch by merging it into master and now everything is back to normal and problem is solved.

Sheraz Ahmad Khilji
  • 8,300
  • 9
  • 52
  • 84
  • I have run into similar issues before. To my understanding, case sensitivity issue seems to be a problem on windows only. I guess you are developing on windows? – Ji_in_coding Jun 13 '19 at 17:58
3

Move files, instead of delete

One way of avoiding deleting files is to move them instead. For example:

cd "`git rev-parse --show-toplevel`"
git checkout 2>&1 | while read f; do [ ! -e "$f" ] || mv "$f" "$f".bak; done
gmatht
  • 835
  • 6
  • 14
3

that's easy to solve, git is saying that you have the same files in both branches, therefore you have to delete the specific files from master branch and then you will be able to merge:

git merge "your branch"

I hope it works for you, I just solved my error. my error was:

error: The following untracked working tree files would be overwritten by merge:
        .vs/slnx.sqlite
Please move or remove them before you merge.
Aborting

Now it is working! In my case .vs/slnx.sqlite was generated by visual studio, I needed to close it before delete it.

Wolfson
  • 1,187
  • 17
  • 22
jeirueda
  • 123
  • 1
  • 1
  • 5
2

This could be a permission issue,

change the ownership,

sudo chown -v -R usr-name:group-name folder-name
Won Jun Bae
  • 5,140
  • 6
  • 43
  • 49
  • I also had the same issue as Won. I added a .gitignore to a folder that was already getting tracked. I deleted the file and then was able to do a git checkout. – cbloss793 Oct 18 '16 at 21:27
2

2 files with the same name but different case might be the issue.

You can Delete one on these files or rename it. Ex:

Pdf.html.twig (The GOOD one)

pdf.html.twig (The one I deleted)
Skatox
  • 4,237
  • 12
  • 42
  • 47
Samuel Vicent
  • 991
  • 10
  • 16
1

If you have renamed a file locally and then do a pull, it will display that error message.

Lyuboslav
  • 405
  • 6
  • 12
  • How to get over this error in that case? This message also appears when switching branches after changing the case in a file name (MyFile => myfile). – Bernhard Döbler Nov 22 '17 at 18:55
0

In my case, I was seeing this error because I am using a popular open source CMS and the directory which was causing issues was the uploads directory which the CMS writes to.

So what it was saying is that there are files which you don't have, but which you can't get from versioning.

I'm grabbing all the files from the live site to my local, then I'll check this into the repo in the hope that this fixes the issue.

0

Delete .gitignore file from appname/gen/ to solve this issue.

vishnuc156
  • 940
  • 12
  • 10
0

I just went to the file system and deleted the file directly, then continued with git checkout and it worked.

I've had the problem occur several times and it may be related to developers doing delete, push, re-add, push or some such thing.

Phil Carter
  • 1,265
  • 1
  • 10
  • 9
0

Most of the answers consider deleting or removing the files, which is the easy way. But sometimes you don't want to get rid of the local files. But merge with a strategy, so git has solution for this too ;

git merge --strategy=ours master 
Erdinç Çorbacı
  • 1,187
  • 14
  • 17
0

Just delete the files or rename them.

e.g.

$ git pull
Enter passphrase for key '/c/Users/PC983/.ssh/id_rsa':
error: Your local changes to the following files would be overwritten by merge:
        ajax/productPrice.php
Please commit your changes or stash them before you merge.
error: The following untracked working tree files would be overwritten by merge:
        ajax/product.php
Please move or remove them before you merge.
Aborting
Updating a04cbe7a..6aa8ead5

I had to rename/delete ajax/product.php and ajax/produtPrice.php.

Don't worry, git pull will bring them back. I suggest you to rename them instead of deleting, because you might loose some changes.

If this does not help, then you have to delete the whole Branch and create it again and then do git pull origin remotebranch

Black
  • 18,150
  • 39
  • 158
  • 271
0

In order to save the modified files and to use the modified content later. I found this error while i try checking out a branch and when trying to rebase. Try Git stash

git stash

0

Check if any folder name having '/' or any special symbol then rename that folders. Then you just clone the repository to another location.

Codemaker2015
  • 12,190
  • 6
  • 97
  • 81
0

A simple solution might be: Just make sure that you are in the correct working directory in GitBash. That Message occure almost every time if a User tries to merge a directory too high in his folder hierarchy.

Example:

/workspace/git/myBashSourceFolder/myProjectSourcefolder

Scenario: User cloned repo in git-folder he created a new Java Project in Eclipse, imported the cloned repo. Eclipse set myProjectSourceFolder as Source Folder in his local Project. therefore the User entered it in git bash and pushed, pulled and commited his project from there. git syncs therefore myProjectSourceFolder - but has no record in his history for myBashSourceFolder. Therefore a push / pull /merge from myBashSourceFolder will produce the given output, if User tries to sync from there next time, instead of the folder he worked before.

Solution: Enter correct Folder and try a pull again. In almost every time I encountered, this solution worked fine :)

mZed
  • 339
  • 2
  • 7
0

In my case the problem was due to a file name changing from subscribe.ts to Subscribe.ts.

So I checked if my branch dev was up to date with current branch I was in, main.

(current branch main)

  1. git merge dev

    > Already up to date

  2. git branch -d dev

  3. git checkout -b dev

crg
  • 4,284
  • 2
  • 29
  • 57
0

I preferred the following that will REMOVE or DELETE all of the files mentioned by the error: The following untracked working tree files would be overwritten by checkout:

# make sure you don't need those files before running the following.
# Otherwise, commit the files in case you would like to have it later

git checkout develop 2>&1 | xargs rm
caot
  • 3,066
  • 35
  • 37
0

When using git switch, you can use the -f / --force / --discard-changes flag:

git switch -f $BRANCH_TO_SWITCH_TO
Abdull
  • 26,371
  • 26
  • 130
  • 172