Hmm.. I'm using git on a daily basis and you could say that we're close.
Maybe a short introduction to the minimal stuff you need when working with git (because all the tutorials out there seem to include all the additional stuff that you need once per month or once per year) and some best practice for teams should help.
Here's how I start (I'll use command-line only because the GUIs often make things worse)
Step 1. Create a folder
/dev/mygame
Step 2. Initialize repository
> git init
Initialized empty Git repository in /home/user/Documents/dev/game/.git/
Step 3. Get the status of your repository
> git status
Initial commit
nothing to commit (create/copy files and use "git add" to track)
This will show you changes and stuff you need to commit or pull.
Step 4. Create & add some files
folder/ binaryfile binaryfile2 great_stuff.txt hello.txt image.jpg
Step 5. run git status again (I do it a lot)
> git status
On branch master
Initial commit
Untracked files:
(use "git add <file>..." to include in what will be committed)
binaryfile
binaryfile2
great_stuff.txt
hello.txt
image.jpg
nothing added to commit but untracked files present (use "git add" to track)
Step 6. Just add everything
> git add .
> git status
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: binaryfile
new file: binaryfile2
new file: great_stuff.txt
new file: hello.txt
new file: image.jpg
Git now knows what you want to commit.
Step 7. Run git commit and write a message
> git commit -m "Added X and Y and did Z"
[master (root-commit) 168087d] Added X and Y and did Z
5 files changed, 0 insertions(+), 0 deletions(-)
create mode 100644 binaryfile
create mode 100644 binaryfile2
create mode 100644 great_stuff.txt
create mode 100644 hello.txt
create mode 100644 image.jpg
Step 8. run git log to see your latest entries
> git log
commit 168087d6156a3dd9dc0edc9d357a4f455f1dfe86
Author: Sylvius <[email protected]>
Date: Mon Oct 5 21:57:07 2015 +0200
Added X and Y and did Z
This is all you need if you're the only person working on the repository! With that, you're able to check out old versions.
The workflow is as follows:
Change your stuff, run git status, add everything you want to add (you can use wildcards *) and commit.
____________________________________________________________________________
If you're not the only one working on your game (First Team Member):
Step 1. Initialize a repository on the server:
git init --bare mygamename.git
Initialized empty Git repository in /media/Elements/git/unityprojects/mygamename.git/
Step 2. clone the repository on your local machine
git clone [email protected]:unityprojects/mygamename.git
warning: You appear to have cloned an empty repository.
Checking connectivity... done.
The domain is username@domain:(homedirectory of username)/folder.git.
However, you can always use services like bitbucket.org to create repositories on their servers.
Step 3. Do all the stuff you did in the first section
* Add Files
* Change Files
* Copy and Paste, Move Stuff
Git will know about these changes
Step 4. Run git status
> git status
Untracked files:
(use "git add <file>..." to include in what will be committed)
hi.txt
smallimage.jpg
stuff/
Step 5. Add everything and commit
> git add .
> git commit "Added YX and ZY"
Step 6. Run git push
> git push
Counting objects: 4, done.
Delta compression using up to 6 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (4/4), 315 bytes | 0 bytes/s, done.
Total 4 (delta 0), reused 0 (delta 0)
To [email protected]:unityprojects/mygamename.git
* [new branch] master -> master
Your repository is now up to date.
__________________________________________________
But we're multiple people! How do we do that?
Step 1. You have the repository, now get your own branch:
> git checkout -b "myname"
Switched to a new branch 'myname'
Step 2. Make your changes, add everything, push everything. Maybe the server will tell you, that the branch does not exist:
git push
fatal: The current branch odrez_branch has no upstream branch.
To push the current branch and set the remote as upstream, use
git push --set-upstream origin odrez_branch
Do exactly as it says and run git push with --set-upstream.
Step 3. Everyone has it's own branch
> git branch
my_branch
another_person
* another_person_2
master
Step 4. Merge
One person checks out his local master:
He makes sure he has the newest version of master
He then merges each branch step by step:
> git merge origin/my_branch
Updating 1bbfb20..616ab6d
Fast-forward
other_stuff.xml | 0
stuff.xml | 0
2 files changed, 0 insertions(+), 0 deletions(-)
create mode 100644 other_stuff.xml
create mode 100644 stuff.xml
> git merge origin/another_person
...
> git merge origin/another_person_2
...
This should not fail. If this fails, it's because people commited changes to the same files!
Of course it's difficult for git to guess which changes are good to use.
Auto-merging hi.txt
CONFLICT (content): Merge conflict in hi.txt
Automatic merge failed; fix conflicts and then commit the result.
You should avoid that in general. Merging is ugly stuff.
git will produce things like that:
++<<<<<<< HEAD
+hallo
+hallo 2
++=======
+ hallo 3
+ hallo 4
++>>>>>>> my_branch
So the file now contains both stuff. Bad. Copy the changes from my_branch (or master) and run
> git checkout --theirs hi.txt
or
> git checkout --ours hi.txt
To use either the original file in the master branch or the new file in the other persons branch.
Now copy the changes to the new file how you want it to be:
hallo
hallo 2
hallo 3
hallo 4
Step 3. What a ride, now add everything, commit and push
> git add .
> git commit -m "Merged branches back to master"
> git push
You master branch now contains all the changes made by individual teammates.
You can checkout a version now if you want:
> git checkout -b v.0.0.1
> git push --set-upstream origin v.0.0.1
and go back to your branch:
Merge master to your branch:
This should not fail, since you already resolved conflicts while merging my_branch to master previously.
Step 4. Start working again
This is a very basic workflow that works great for smaller teams.
____________________________
But WHY?
- Git is decentralized, so you can easily clone the complete repository, move it to somewhere else, work offline, stuff like that
- Git knows about changes in your folder without needing explanation. SVN is a beast when it comes to moved folders, files, deletions etc.
- A Git Server is really easy to setup, runs 100% reliable and is lightweight. SVN will let you check the server and fix things on a daily basis.
- Git is extremely powerful and there are a lot of cool Web and Native GUIs for it.
Git is sexy.
And don't forget about .gitignore!
folder/ignored_subfolder
ignored_folder/*
*.ignored_fileextension
This will stop git from tracking e.g. IDE specific files and big binaries.