Reputation: 423
I'm really new at GIT. My aim is to sync my Eclipse Projects between PC / Laptop - and I thought it would be a good Idea to use GIT for this. So I've set up my Repository, got it into Github, etc.
I have written a small Bash-Script which should do the sync work for me. It seems to work, but I'm not sure this is the best way to do:
#!/bin/bash
# Github Syncro Script
# SoftwareProjekte
cd "D:\Projekte\Software Projekte"
git add .
git commit -a -m "Auto-Git-Backup $(date "+%d.%m.%Y %H:%M "|sed -e ' s/\"/\\\"/g' )"
git push -u origin master
git pull
Is this a good Idea? Should I use something like http://code.google.com/p/git-sync/ instead? What bugs me about this script is that I have to enter my Password two times.
Upvotes: 3
Views: 2584
Reputation: 423
Now I think i've learned a bit about GIT and my new Syncro-Script looks like:
#!/bin/bash
# Github Syncro Script
git pull
git add --all
git commit -m "Auto-Git-Backup $(date "+%d.%m.%Y %H:%M "|sed -e ' s/\"/\\\"/g' )"
git push -u origin master
git add --all
seems better than commit -a
because it adds new files and also removes deleted files.
It also looks like that I have to pull (and merge my remote changes with my own) before I can push my local changes. (In Case of Conflict)
Is this correct?
By the way: This article / graphic helped me a lot to understand how GIT Repositorys work: http://gitready.com/beginner/2009/01/21/pushing-and-pulling.html
Upvotes: 0
Reputation: 5586
I use scripts like this to work with git, it's nice because you can develop your custom script as you learn more features, there are other tools out there but it justy comes down to personal preference.
One thing I would say, to sync from git it's as simple as
git pull
If you are commiting to git first you should be doing a pull to reduce the risk of the local copy being an old version and creating conflicts.
Something like this:
cd "D:\Projekte\Software Projekte"
git pull
git add .
git commit -a -m "Auto-Git-Backup $(date "+%d.%m.%Y %H:%M "|sed -e ' s/\"/\\\"/g' )"
git push -u origin master
Upvotes: 2