2

I have a personal repository managed by git. In There, I have small project with tracked files I already commit and some untracked files I want to add in near future.

Those untracked files are in my local computer. I have no backup. I wonder if it is a good practice to create new branch for untracked files from my develop branch (I have master, develop and one per feature I am working on).

git checkout -b myuntrackedfiles develop
git add <files> (each untracked file)
git commit -m "Backup"
git push origin myuntrackedfiles.

Then when I want to incorporate one of those untracked files, I just copy them from untracked repository to desired branch

git checkout myfeature-nnn
git show myuntrackedfiles:myfile > myfile
git show myuntrackedfiles:myfile2 > myfile2
...
git commit -m "Adding untracked files"

git push origin feature-nnn

Finally, I can remove them from untracked branch

    git checkout myuntrackedfiles
    git reset --soft HEAD~1
    git reset HEAD myfile1
    git reset HEAD myfile2
    git commit --amend
    git push origin myuntrackedfiles

And delete locally the untracked files.

the question is: Exists a better and efficient way to do this process or this one is fine enough?

2 Answers2

2

Git is not a backup tool. Best practice is to commit files that are required for your project to run. Be careful though that these files don't need modified for another developer to run or for you to run on a different machine. Such changes should be isolated to configuration that can be set outside of the code, such as through environment variables or a config file that can be read by the app during run-time.

You should avoid committing large files, such as data used by the app. Instead, you can back these up using a tool such as Drop Box, OneDrive, or Google Drive.

Code-Apprentice
  • 81,660
  • 23
  • 145
  • 268
  • My scenario is single developer. Untracked files are files that I don't finish yet to consider making a commit or files that will be added to the project but not in this phase. Sometimes I deveop an idea for a project but it is just a piece that need revision. I don't want to lose the code. If it is untracked means it is on local laptop or PC. Google Drive and Dropbox are good. I used to use them as a backup due sometimes I work in several machines. But the idea of using one tool for this looks like better. – Roger Manich Nov 01 '20 at 12:35
  • @RogerManich For any in progress work, create a new branch. You can commit the unfinished files on this branch. When you finish the work, merge the branch into your main branch. This is more about keeping track of work in progress rather than just backing up files, which is exactly what git is made for. – Code-Apprentice Nov 02 '20 at 15:50
  • @RogerManich Each commit doesn't have to be a finished feature, but it should compile and run. Also tests should pass on each commit as well. – Code-Apprentice Nov 02 '20 at 15:52
2

Well, as the question is untracked files...

$ git ls-files --others --exclude-standard -z |\
xargs -0 tar rvf ~/backup-untracked.zip

Source opensource.com

cEz
  • 4,932
  • 1
  • 25
  • 38