Name Mon Lu

Love jQuery/CSS

Blog about Webdev

Twitter supawaza

RSS Twitter Flickr

What I am up to:


Archive for the ‘Git’ Category

I’ve known suberv­sion for a while, I didn’t use it that because I’m like a one-person-web-army, so I didn’t find the use for it and used Baz­zar – which you could do ver­sion con­trol by folder and with a nice GUI built in. The only rea­son I didn’t do a full blown ver­sion con­trol with Baz­zar was that there weren’t a lot of free hosts that host Baz­zar and I didn’t feel like installing one.

Why Git > Sub­ver­sion – a short intro

Sub­ver­sion is like a tourist bus, every­one has to get there at the same time and check in, if one’s miss­ing – oh crap.  If the bus crapped out, you ain’t going any­where either. Git is like a rental car, you check in when you’re done using it. If your car broke down, you can replace it with another. I thought this anthol­ogy makes sense if you want to visu­al­ize it.

Back to the nerd terms, here’s what they are. So finally, I just started a new job that I actu­ally work in a team that use Sub­ver­sion. It’s great and all, I still don’t like it as much.  Biggest prob­lem as peo­ple know is Sub­ver­sion is a cen­tral­ized ver­sion con­trol sys­tem, if the server is down, so are you. Well, not com­pletely, you work on your local copy, when the server is back up, there will be A LOT OF messed up merg­ing to do because it can’t keep tracks of what you’ve done up to that cer­tain point.  You are actu­ally wast­ing time.  Not to men­tion it has its own file struc­ture, it’s pretty “tidy” in a way. If you work like a mess like me, Baz­zar and Git are our heroes. Git is pretty much like Baz­zar, that you can do ver­sion con­trol in ANYWHERE you want.  You don’t have to have to let a server knows what you are doing in every 5 min­utes to keep things in check, you can just do it locally.  So imag­ine the server goes down for an hour, in that one hour you drew a nice look­ing dragon from your what­ever, col­orized it, added wings etc… and com­mit each of the change. When the server comes back up.  You tell the Sub­ver­sion server, hey, I did these. The server goes… what the hell are these craps?? I knew NOTHING about the dragon… it reminds me of my dad kicked my ass one time while I tried to explain why I didn’t do my home­works, because they were READING ASSIGNMENTS!!!  Now THAT’S a git!

Instead, Git tracks them all offline, so if the server goes down, who cares.  When it’s back up, you can tell the server what you’ve done, how many changes you’ve made, you drew a dragon, added some flames etc… the server WILL know what you did and so will every­one else because it keeps track all the ver­sions offline. So when you “push”, you are actu­ally upload­ing the old AND the new ver­sions to the server.  Bet­ter yet, if the server goes down in flames, you can just find another one, upload what you have and all good to go again. Imag­ine the Sub­ver­sion server goes down in flames… I can’t… I just can’t!  I don’t wanna think how to recover all of my awe­some drag­ons! I lied, you can, just not with all the ver­sions you’ve made. Just need to start a new one… me thinks…

Okay okay, here’s the 5 steps to setup Git to a remote server

Enough drag­ons, I’ve read at least 20 blogs, 10 docs to piece together how peo­ple can make the sim­ple setup process hard.  It’s not hard, but they’re just not on the same page for some odd rea­sons.  For the record, NOT every­one uses Github… I use unfud­dle

  1. Sign up an account on either Github or Unfuddle
  2. Go to Git-scm.com‘s down­load page to get msys­Git (full ver­sion to make things sim­ple – not the portable one) - just fol­low the steps for instal­la­tion… then it’ll ask you Select either Git Bash or Win­dows Com­mand - I’m not that smart, but I pre­fer to look smart, so I chose Git Bash over win­dows cmd. It’s just like win­dows cmd any­ways with a few nerd commands.
  3. For remote hosts such as Unfud­dle or Github – they’ll need a SSH key to authen­ti­cate the con­nec­tion to their servers.  Each com­puter needs a new key, so if you are home, needs one. At work, needs one. At your ex’s house steal­ing his stuff, needs one. With­out it, you can’t get in, sim­ple as that. So let’s get that out of the way first. So let’s do this the easy way with­out typ­ing much.

    Open up Win­dows Explorer, find a folder, really, any folder, right click on it and you’ll see “Git GUI here” – click on it. You’ll see a box come up.  Click “Help” -> “Show SSH Key”.  If you see a blank box – click on “Gen­er­ate key” (Screen­shot).  Copy all of that to:

    • Github -> Account Set­tings -> it’ll nag you if you don’t have a SSH key added yet. So add it.
    • Unfud­dle -> Per­sonal Set­tings (top right) -> Scroll down you’ll find the box then paste all of it in also (give it a name if you want – I do Home, Work)
  4. For the pur­pose of learn­ing, I highly rec­om­mend using Git Bash – if you learn the com­mands, you’ll under­stand how to use Git GUI later.  First, go to the folder that you would like to start ver­sion con­trol (just use your win­dows explorer) – then right click on the folder “Git Bash here”.  A linux com­mand prompt thingy pops up.
  5. Cre­ate an new repos­i­tory on Github or Unfuddle
    • Github: believe it or not, Github gives you ALL of the instruc­tions you need!  So just type what they show you, then you’re good to go!
    • Unfud­dle: same for unfud­dle but they won’t show it to your face. After you’ve cre­ated a new repo, click on “Repos­i­to­ries” – you’ll see the new repo you just cre­ated, click on it then you’ll see the instructions.

Really, that’s all to it for set­ting up a new repo server to work with, but for some­one who don’t know much about com­mand prompts / shells stuff, it was hard and I’m sure some­one else out there had the same problem.

What gives?! Remote hangs???

If you see “Remote hang” – two possibilities:

  1. You need to wait for the SSH key a bit longer (if you didn’t do it in step 3 – which should give it enough time, if not, wait a few more minutes)
  2. You’ve entered a pass­word when you cre­ated a SSH Key. So if this hap­pens, make sure you leave the pass­word fields empty.  If you use Git Bash to gen­er­ate the key, just hit enter twice when it ask for pass­word. When you’re done, add the SSH-Key back in step 3 – wait a minute a two then try again.

Ignor­ing Files

Along the path, I’ve asked the same ques­tion and it took some dig­gings to find.  If you have a few files you want to do ver­sion con­trol, but want to skip files like .DS_Store, .project, .fla or whatever.

Ignore Files Way #1

  1. Dur­ing “git add .” – instead of doing that.  Just do:
    git add filename.html filename.jpg
    You can add as many files on one line as you wish – DON’T com­mit yet
  2. Type “git sta­tus” – you’ll see a list of “untracked files” – make sure those are the files that you DON’T want to track (ver­sion control)
  3. Then type:
    git ls-files -o --exclude-standard >> .gitignore

    What this does is it will ignore all the files those were showed in “untracked” – then cre­ate the .git­ig­nore file for you

  4. After you’re done: “git add .git­ig­nore” then commit

Ignore Files Way #2:

  1. Fire up notepad and add the file names that you want to ignore. Exam­ple:
    .project
    .DS_store
    whatever.jpg
  2. Save the file inside the same folder where you just ini­ti­ated a Git and name it ignorefiles.txt (or what­ever you want – some­thing simple)
  3. Open up or switch back to Git Bash – assum­ing that you didn’t change direc­tory and didn’t close it (oth­er­wise, just go back to the folder and do a “Git Bash here”). Type “ls” to see if “ignorefiles.txt” is there.  If not, make sure you save the file here.  Oth­er­wise, type the fol­low­ing to change the file name to “.git­ig­nore”:
    mv ignorefiles.txt .gitignore
    git add .gitignore
    git commit -m "Added .gitignore"

You would say why not just change the file exten­sion inside Win­dows Explorer? Well, go try it, then you’ll see why. I’ll wait……… Done? Worded. As you can see, way #1 is eas­ier.  If you did way #1, and want to add more files later, it cre­ated the .git­ig­nore auto­mat­i­cally for you, so just dou­ble click on it and point it to Notepad to open it up.  Or Git Bash it…

Remove Files from Tracking

One more thing I found myself won­dered was how the heck do I remove one of the files after it got tracked?? Sim­ple:
git rm --cached filename
I’ve seen peo­ple tell oth­ers to do: git rm filename

That will delete your file for you, too! Did they even read the ques­tion??  I pre­fer remov­ing it then add to the ignore list, I don’t feel safe remov­ing a file phys­i­cally even though I got Git to watch my back.

Any­ways, these are the stuff I’ve ran into when I first try­ing to setup my work­space, hope this helps.  Once you’ve fin­ished this, you’re pretty much up and run­ning.  Refer to:  http://git-scm.com/documentation for tons of good­ies info.