Either track or ignore.
Track: Add untracked file to another branch
I’ve got a branch dev/branch
with untracked files A, B
.
I’m happy to delete or stash B
but I’d like to add A
to another branch test/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).
https://stackoverflow.com/questions/835501/how-do-you-stash-an-untracked-file
But, this has multiple parts.
1. let’s get rid of B
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.
- stash:
git add B;
git stash
- delete:
rm B
2. let’s move A
to test/branch
git checkout test/branch
git add A
etc
Notes:
Current docs say working directory
but, as of 2.9.1, will read working tree
.
https://stackoverflow.com/questions/39128500/working-tree-vs-working-directory
Ignore: just ignore untracked files
I’ve got a feature branch with a custom entry in .gitignore
to ignore *.out
.
However, I now checkout master
and 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 .gitignore
.
https://hackernoon.com/exclude-files-from-git-without-committing-changes-to-gitignore-986fa712e78d
Note: if you just want to temporarily exclude a file you can use:
git update-index --assume-unchanged <file>
http://gitready.com/intermediate/2009/02/18/temporarily-ignoring-files.html