Help with git

Community Forums/General Help/Help with git

ziggy(Posted 2012) [#1]
I'm planing a project and I was considering using git instead of svn because I've read several good reviews and I've seen people I trust recommend it over SVN. But any getting started guide I've seen is very impossible to follow, as it just tell which commands to use, without explaining them or telling what tye do, nor a simple information of what git exactly is, and how it is designed to work. I've seen commands like clone or push or commit, no idea how all those commands work and what are they suposed to do, and how data is organized on a git repository, etc etc etc.
Does anyone here have A GOOD, well explained, properly ordered, functional and detailed getting started guide or resource?


therevills(Posted 2012) [#2]
I tried Git, but then went with Mercurial because of the TortoiseHg was so much easier at the time.

Just wondering why you have chosen a distributed source control over SVN this time?


D4NM4N(Posted 2012) [#3]
PLEASE back up your project folder before trying this! I am not 100% sure as i almost always use a client gui app and a server side terminal.

I also use linux(server and client), osx(client only), windows(client only) so while osx will likely be samish to linux, I have no idea what happens server side on windows. (however the basic principles will be the same).


Git basically works like this (t least the way we use it):

your project folder ---------------------commits to------------------->.git folder INSIDE your project folder (this is essentially your own personal version control repository)
.git folder in project folder<------pulls from and merges with-------remote version (optional) and updates to your project folder You cannot do this if you have unstaged(non-commited) changes
.git folder in your project folder----------pushes to -----------------> remote version (optional) You cannot do this untill you pull first if not up to date.



------------------------------------------------------------------------------
If you have a server, (not essential see below) assuming you have added a git user:

git --bare init

run this command from the folder you want to use as the repo on server for example: "/home/git/myproject.git" (myproject.git is a folder!)
Note it does not have to be a -dedicated- server, just another machine running git. You can drop the --bare and still use it as a working machine, syncing your git with a collegues or simply another workstation of yours. Although a "bare" repo on a dedicated machine has obvious advantages. (bare just means it stores the repo in git database form, without an browsable filesystem making it more efficient and safer, especially if you have multiple contributors)

when done, go to your client and do this: (again see docs, but it is something like this):

git clone git@... -make sure in project folder unless you specify a place to put it on the end
or via ssh:
git clone ssh://git@...

Copy your project files into it then to commit to local repo:
git commit -a (on osx/linux you will need esc + ":wq" to get out of the horror that is vim after writing a comment)

to sync and merge remote with local repo:
git pull

to push your changes from local repo to remote:
git push


By "local repo" i mean the ".git" folder in your project structure. This is a local repository of your project containing branches history etc... so handle with care. When you push and pull this synchronizes with the remote copy.

------------------------------------------------------------------------------

You do not actually need a remote server, you can, if you want just a versioning system, is commit to the local and then back the .git folder up manually like you would any other.
To set up just a local repo (without a server) i think you just run

git init

in an empty folder you want to use as your project folder.
then copy your crap to it and commit it with:

git commit -a


------------------------------------------------------------------------------
PS: I reccommend adding all your build folders to the .gitignore file (see docs) which is just a text file in project folder with a list of stuff that yo do not want in the repository.

As far as branching and reverting goes, see the docs! (I use a gui client to do this so have no idea what the command line is)

Last edited 2012


nrasool(Posted 2012) [#4]
I'm with therevills, I chose Mercurial as well over Git, Tried git but like the name says it was a "git" to work with ;-)

I still prefer SVN but Mercurial is pretty good and the workflow for me works using xp-dev

BTW nice steps D4NM4N


ziggy(Posted 2012) [#5]
Thanks D4ANMAN, (and everybody else) now I understand a bit more how git is supposed to work...


Warpy(Posted 2012) [#6]
gitref.org is good.


_PJ_(Posted 2012) [#7]
I've been using TortoiseSVN a lot, and found it really quite agreable, but a friend of mine has been recommending git as far superior for collaborative works. I've yet to have a good proper look, but I do trust my friend's knowledge and experience in these matters :)