Adding untracked file to another branch
I’ve got a branch
dev/branch with untracked files
I’m happy to delete or stash
B but I’d like to add
A to another branch
How do I do that?
The easiest would have been if you were happy to stash them all. Then you could do
git stash --all(which includes untracked and ignored files).
But, this has multiple parts.
1. let’s get rid of
If we don’t know what to do with
B, e.g. you don’t have time to look at it, then stash it. Otherwise, delete it.
git add B;
2. let’s move
git checkout test/branch
git add A
Current docs say
working directory but, as of 2.9.1, will read
Ignore untracked files
I’ve got a feature branch with a custom entry in
.gitignore to ignore
However, I now checkout
masterand find I’ve got a whole load of untracked files.
I don’t want to add it to the global
.gitignore as I don’t want to change the behaviour for other developers.
Neat trick: add it to
.git/info/exclude which acts as a local
Note: if you just want to temporarily exclude a file you can use:
git update-index --assume-unchanged <file>