I’m new to git. I have remote git repo on my server which contains master which is the current version of my code. On my local computer I have old versions (about 10) of this code just stored elsewhere from before I was using version control (just plain files).
Even though I probably will never need the old versions again, I’d still like to add them to the repo so if I ever wanted to check an old version I could do that.
So how do I do this, do I add them as branches or tags and how should I go about adding them to the remote repo?
Right now I do this: just delete ALL the current version code (already committed and pushed to server), copy and paste in the old code files (say version 0.2) and create new branch (version0.2), commit that and then push to server. Now I got 2 branches, master and version0.2. Should this be the correct way?
Your system is fine, however if the old code actually lead to where master is I’d recommend stitching everything together into a single branch once all the code is in the repository. I’m assuming that this is a private repository and messing with master isn’t going to effect anybody else (rewriting history on a public repository isn’t nice).
That being said I also assume you have a bunch of branches similar to the following branches:
In this case v0.1 is the oldest, v0.2 built on v0.1, and so on. To actually make master represent this I suggest rebasing branches in order so that at the end master contains the code from all the branches. The steps to do this are:
git checkout v0.2git checkout -b REBASE_v0.2git rebase v0.1git rm FILEeach file.git checkout v0.3git checkout -b REBASE_v0.3git rebase REBASE_v0.2git rm FILEeach file.git checkout mastergit checkout -b REBASE_mastergit rebase REBASE_v0.3git diff mastergit checkout mastergit branch master_oldgit reset --hard REBASE_mastergit branch -D REBASE_v0.2 REBASE_v0.3 REBASE_masterOnce you’re certain that everything is good you can go ahead and get rid of original branches:
git branch -D v0.1 v0.2 v0.3 master_oldAt this point you should just have a master branch with your actual code progression.