Roger
Roger

Reputation: 101

Git Backup untracked files

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?

Upvotes: 2

Views: 666

Answers (2)

cEz
cEz

Reputation: 5062

Well, as the question is untracked files...

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

Source opensource.com

Upvotes: 2

Code-Apprentice
Code-Apprentice

Reputation: 83527

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.

Upvotes: 2

Related Questions