Sorry in advance if this question is too related to other git merge
questions. I just have the feeling that I haven't understood git well up to now...
I developed something which I call my 'todo list app'. It's a shell script to print a todo-list, sort the rows, add new rows, delete rows etc. Pretty handy! The todo-list is a txt-file saved on the hard drive. Whenever I call the todo command, it pulls the newest version of the txt-file from my Github repo to the machine I'm working on, edits the local file, and pushs it to Github again. By that, I can use the 'app' on different machines while having always the most recent todo-list available.
# get newest todo-list version
git -C ~/GITHUB/ fetch #git -C enables to use the todo-list-app in every dir
git -C ~/GITHUB/ checkout origin/master -- todolist.txt
# add, remove, (or just print tasks) and write changes to file
shelltodolistfunction
# push changed file to Github again
git -C ~/GITHUB/ add ~/GITHUB/todo-list-app/inbox.txt
git -C ~/GITHUB/ commit -m "update inbox"
git -C ~/GITHUB/ push
Fetching, pulling, and pushing is kind of slow. Because of that, I would like to add another flag to the todo-list (for the sake of convenience, I haven't shown the getopts structure of the app here), so that it only 'updates' (i.e. does the git stuff) when called like e.g. todo -update -rmtask "ask stackoverflow" -addtask "bake a cake"
.
However, this could lead to the problem, that there is a newer version on Github, while I apply some changes to an older version locally. When calling todo -update
, I would like the app to automatically merge these two files, save the merged file locally and also push it onto Github.
Github version:
write todolist app
ask stackoverflow
plan holidays ### <- this line would not be on the local version before an update
Local version:
write todolist app
### ask stackoverflow # <- this line has been deleted locally
bake a cake # <- this line has been newly added
New version:
write todolist app
plan holidays
bake a cake
Can this be done automatically and does it make sense?