Score:1

Using git and github to share a folder content that has to be updated daily

ng flag

I have a folder that I want to publicly share with others, the content of the folder suppose to be updated daily: some files gonna be changed, some are deleted, some are added. I would like to use GitHub for that and create a cronjob that supposes to handle the repository updates. What kind of git commands do I have to use if I always want to have an exact copy of the local folder on my git repository.

This is the code that I am planning to use but I have doubts about locally deleted files (if it is cover them or not)‍♂️:

cd ~/myfolder
git init
git add .
git commit -a -m "$current_date"

Thank you.

Score:0
jp flag

That code is almost correct for the initial setup of your repository, there's a few more steps you need to add to the end:

git branch -M main
git remote add origin [email protected]:username/repository-name.git #Edit this to match your Github repo
git push -u origin main

The first line I've added sets the branch on git (Github default branch is main), the second line sets the remote origin, and the final line pushes your folder to Github.

The script you call from crontab should look like this:

cd ~/myfolder
git add .
git commit -a -m "$current_date"
git push

Assuming you named it upload-script.sh, this is the crontab entry, which will run at every minute (the fastest interval crontab allows) with no output:

* * * * * ~/upload-script.sh >/dev/null 2>&1

I'm not sure if you can ger rate-limited by Github for this, so you might need to decrease the speed of pushes. You can generate crontab entries using crontab generator if this is the case.

And for reference, here's Github's documentation on how to set up a remote repository (helpful for debugging git issues): https://docs.github.com/en/get-started/using-git/pushing-commits-to-a-remote-repository

Hope this helps :)

Ra Spirit avatar
ng flag
Thank you very much for your overall answer. I have noticed that the .git folder is used a lot of space. I was doing some research and I found 2 more commands to reduce the size of the folder which is: `git fsck` `git prune` My question is should I use them? as I said I don't need any history of the files. Also, it would be wonderful if there is a way to get the repository without .git folder or with a minimum size. Of course, I can delete the folder after but I am worried about the bandwidth which I would like to save. Thank you!
Ra Spirit avatar
ng flag
Is that make sense to make the code like that: `cd ~/myfolder; git fsck; git prune; git add .; git commit -a -m "$current_date"; git push`'
Pranav Sharma avatar
jp flag
Honestly, if you’re not needing the history then there’s better methods to do this than Git (e.g. cloud storage, localexpose services), but your changes should keep the size of .git to a minimum. Also, Git doesn’t upload the entire repo every time you push, only the files which have changed since the last push (see this question on SO: https://stackoverflow.com/questions/26005031/what-does-git-push-do-exactly ).
Pranav Sharma avatar
jp flag
Also I noticed you’re fairly new to SE, so welcome :) if my answer fulfilled what you need, please accept it so that other people can see what helped you.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.