Search code examples
gitversioning

Novice question about Git versioning for single user/multiple computer


Until now id do versionining with subfolder for each version and sync betwen computers with syncthing. It works but it's easy to do mistake editing wrong version and similar. So I was thinking to switch to some versioning software. Git seems to be capable to do that and much more. But seems that Git offer to much and I can't see correct way to do.

For example I do make project folder and write .gitignore file with list of files I don't want to be in Git (mostly compiling results) After that I do write some sources and then issue:

git add .
git commit -a -m "the commit remark"

And I assume that I need to issue that commands every hour on so. So I can revert if I do some stupid mistake. Now I have the question when I got some stable code I want to name that as version v1.0. How to do that correctly? Do I need to make branch or is enought just to make tag? And when I have v1.0 how to continue work for future v1.1? Should I work on master or is best to create branch v1.1 and do job here. If I do some minor change on v1.0 will that appear on v1.1 too?

Now I have 3 computers (work, home, laptop) and I use syncthing to keep all of them in sync. Usually work computer is permanently on and other two on demand. But just I use them. I do small test and seems that even Git repo is synced ok with syncthing. But I wonder that Git has maybe better way to sync all of my computers. But I don't like to have my code on cloud. How to manage that?

Thanks for any help


Solution

  • Creating versions

    Now I have the question when I got some stable code I want to name that as version v1.0. How to do that correctly?

    Git provides tags for this. In order to create a tag, use git tag <tag name>.

    A tag is basically a name for a specific commit. You can check out (get the code) the tag using git checkout <tag name>. In order to get the current version of your code again, use git checkout master.

    Syncing

    I do small test and seems that even git repo is synced ok with syncthing. But I wonder that GIT has maybe better way to sync all of my computers. But I don't like to have my code on cloud. How to manage that?

    git allows you to push (upload) your commits to.a git server and pull (download) the commits later.

    The server (use the computer that is running 24/7) can be created by initializing a bare repository In order to do this, navigate to your server and run

    git init --bare
    

    This creates a new repository without any files checked out (just a server repository).

    In order to do push to/pull from a git server, you need to configure a remote.

    The easiest way to do this is to use betwork shares. After you can access the share, you can configure the remote like this:

    git remote add origin /srv/git/project.git
    

    or on windows

    git add origin Z:\your/git/repository.git
    

    After creating the remote, you can use git push -u origin master and git pull origin in order to push/pull.

    If you don't want to use network shares, you can use an SSH or smart HTTP server.

    More information can be found in this chapter of Pro Git.

    Other tips

    I would not automatically commit and push every hour or similar (for software projects) but every time you change something.

    You might also want to create a backup before doing anything you are not sure about. Git allows you to restore lost data in most cases (using reflog and checkout) but this is a bit more complicated.