I use Git but I don’t use GitHub (for non shared things). First install Git for your system. Then create a directory where you want to host your repository, for instance a directory named ProjectRepos. This can be a directory on your system, or on a USB drive, or whatever. Inside ProjectRepos, create a directory called project-name.git.
Change directory into project-name.git using your system’s terminal emulator, for example GitBash for Windows, or regular terminal on Linux/Mac. Now issue the command git init --bare
(if you are using a file system that does not support permissions, such as one of the fat family which I use on a USB so I can move between different operating systems, or if you will only be working on the project on one machine) or git init --bare --shared=all
(if you will be using a file system that supports permissions and also will be moving the USB between different machines). You have now created a bare repository to host your project repo in.
Now you can change directory to where you work on your projects. For example say all your projects are in Documents/GDevelopProjects, go into that directory. Now issue the command git clone path/to/bare/repo
. This will create a new directory called my-project instead of my-project.git, and will also give you a warning that you appeared to clone an empty repository. Now copy your project from the directory you were working on it in (if you had already been working on one) or (more usual) begin your new project directly in this directory. There are other ways to do this but this way is most simple for me to explain in text.
From now on you will use this directory for your working on your project.
So first thing first, if you have not set up a global user name or email in Git config you will issue the commands git config --global user.name "Your Name"
and git config --global user.email "youremail@youremail.address"
.The --global
tag is optional, you can leave it out if you would rather create a local user name and email per project/directory which is handy when different projects require different username/email.
Now that Git will know who you are so it can keep track of the author of changes, you will stage the project you have copied into/saved from a new project into this directory. There are a couple ways to do this but for the general purpose you will probably use the command git add -A
. Then you may commit them with a message git commit -m "Look ma I made a repo!"
and now push the changes into your bare repo with git push origin master
(assuming master is the name of your main branch, you can call it something else if you prefer.)
Now your bare repo is caught up with all the work you have done in your work space directory. Every time you make changes you are happy with, you can save your GDevelop project and then stage, commit, push.
Now lets say you want to try something out in your project and you aren’t sure it will work. In GDevelop, make the changes and save the project. In your working directory (you always only work in your working directory, not in your bare repo), you can get out of the master branch (that is perfect and you don’t want to mess up), and start working in this new testing branch. In fact you will probably never work directly on your master branch. So issue the command git checkout -b working
, where “working” is just whatever you want to call the branch you are doing your work in. Now stage, commit and push the changes you had saved in GDevelop that you don’t want contaminating your master branch. The steps are mostly the same. git add -A
, git commit -m "First commit of new changes"
but on the push command, since this is the very first time you’ve created the branch named ‘working’ (by checking it out), do the command git push -u origin working
. After this, any time you are in the branch named ‘working’ and want to push (after you have staged/commit), you may just git push
with no other instructions and it will push to the branch named ‘working’ in your bare repo. Also, you only use git checkout -b nameofbranch
the first time you are creating the branch you are checking out. After that if you had switched back to master branch with git checkout master
and want to go back to the branch named working you would use git checkout working
.
Mkay now continue working and saving in GDevelop. If you are happy to your changes you may stage/commit/push the branch to the branch on your bare repo. If you dislike the changes but have already Saved in GDevelop, you may git status
and look at the changes you have saved in GDevelop but not yet staged for commit, and pick out what you are not happy with and git restore filename
to discard the unstaged changes in working branch. Then refresh your GDevelop session by going to File/Open/Recent/ThisProjectOpenRightNow. GDevelop is refreshed and you will see the changes you discarded with git restore
command are gone.
Ok so you are happy with all the test changes and want to put them all in your perfect working branch. Maybe you are so happy that you decide to change the version number and save in GDevelop and merge as a publishable update! So in working branch still, run git status
. Make sure that you have staged/commit/pushed (-m “Version 1.9.0”) your final changes to working branch. git status
should report ‘nothing to commit, working tree clean’. Good now git checkout master
. Again double check with git status
to see that master in your working directory is same as master in your bare repo with nothing to commit, working tree clean, and not ahead of master by any commits. Now git merge working
. Perfect! Now you can checkout branch working again and get started on something else.
But what if you’ve made a lot of changes and even pushed them to your bare repo, on whatever branch, and now you realize you need to scrap a lot of these changes and get the project back into the state of a previous commit? git log --oneline
will show a list of commits. Pick the commit that comes after what you want to revert to, so if you want to revert to commit 3, select the hash for commit 4 and run git revert --no-edit hash
. The --no-edit
is optional and will just commit your reversion with the default message, but I include it because you might have a really confusing and complex default editor on your system like nano and you are probably too lazy to figure out how to change it to vi, so you just want to avoid writing a message on your revert because you can’t even figure out how to move around in nano without writing jjjjj or 5 G all over the place. Now after that just git push
and your working directory and bare repo are back to where you want them. There is an interesting difference between git revert
and git reset
which you can learn more about if you like.
Anyway Git is really simple and has a lot more that I have not touched on.