1

We are using Git but I have never created any branches for my projects. Now my current branch is terribly cluttered with so many files from different projects, both modified and untracked. Is there a way that I can move file(s) from my current branch into other new ones?

Also, if I do a git checkout -b branch2, what would happen with my current modified and untracked files? I keep seeing conflicting information about them disappearing, specifically with the untracked, so I'm not sure how to proceed since I don't want to lose anything.

Edit: The suggested question doesn't quite cover how to perform this enmasse, nor does it answer my other question, but it IS helpful.

user256430
  • 3,575
  • 5
  • 33
  • 33
  • 1
    git doesn't care about your untracked files, so no, git wouldn't delete your untracked ones. – hanshenrik Jan 04 '23 at 23:21
  • Does this answer your question? [How do I copy a version of a single file from one Git branch to another?](https://stackoverflow.com/questions/307579/how-do-i-copy-a-version-of-a-single-file-from-one-git-branch-to-another) – hanshenrik Jan 04 '23 at 23:22
  • @hanshenrik. That doesn't appear to be the right dupe. – Mad Physicist Jan 04 '23 at 23:49

1 Answers1

2

If you create a new branch from the one you are actually on you are not going to lose any files.
It will just set create a new branch from the last commit on your actual branch. Keep in mind that almost whatever you do (expect git reset and a few other command) you will never lose work.
Conflict happens when you modified some files and an another person also modified them but pushed them, so when you try to pull the new modifications git warn you about two state of the file existing.
Also you can modify the .gitignore if you want track somes of the files that are not.

pgossa
  • 171
  • 9
  • -It looks like all of my files are in the new branch and nothing has changed, so that's great! So now does that mean I can stage and commit the files I want for that branch and then create a new one and just rinse & repeat?? – user256430 Jan 05 '23 at 16:49
  • I have never used branching this way, if I have multiple projects I have always create multiple repositories. But I suppose that way to do this like another, just keep in mind you should modify your .gitignore depending on the branch you are on so. – pgossa Jan 05 '23 at 17:50