I’ve known subervsion 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 Bazzar – which you could do version control by folder and with a nice GUI built in. The only reason I didn’t do a full blown version control with Bazzar was that there weren’t a lot of free hosts that host Bazzar and I didn’t feel like installing one.
Why Git > Subversion – a short intro
Subversion is like a tourist bus, everyone has to get there at the same time and check in, if one’s missing – oh crap. If the bus crapped out, you ain’t going anywhere 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 anthology makes sense if you want to visualize it.
Back to the nerd terms, here’s what they are. So finally, I just started a new job that I actually work in a team that use Subversion. It’s great and all, I still don’t like it as much. Biggest problem as people know is Subversion is a centralized version control system, if the server is down, so are you. Well, not completely, you work on your local copy, when the server is back up, there will be A LOT OF messed up merging to do because it can’t keep tracks of what you’ve done up to that certain point. You are actually wasting time. Not to mention it has its own file structure, it’s pretty “tidy” in a way. If you work like a mess like me, Bazzar and Git are our heroes. Git is pretty much like Bazzar, that you can do version control in ANYWHERE you want. You don’t have to have to let a server knows what you are doing in every 5 minutes to keep things in check, you can just do it locally. So imagine the server goes down for an hour, in that one hour you drew a nice looking dragon from your whatever, colorized it, added wings etc… and commit each of the change. When the server comes back up. You tell the Subversion 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 homeworks, 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 everyone else because it keeps track all the versions offline. So when you “push”, you are actually uploading the old AND the new versions to the server. Better yet, if the server goes down in flames, you can just find another one, upload what you have and all good to go again. Imagine the Subversion server goes down in flames… I can’t… I just can’t! I don’t wanna think how to recover all of my awesome dragons! I lied, you can, just not with all the versions 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 dragons, I’ve read at least 20 blogs, 10 docs to piece together how people can make the simple setup process hard. It’s not hard, but they’re just not on the same page for some odd reasons. For the record, NOT everyone uses Github… I use unfuddle
- Sign up an account on either Github or Unfuddle
- Go to Git-scm.com‘s download page to get msysGit (full version to make things simple – not the portable one) - just follow the steps for installation… then it’ll ask you Select either Git Bash or Windows Command - I’m not that smart, but I prefer to look smart, so I chose Git Bash over windows cmd. It’s just like windows cmd anyways with a few nerd commands.
- For remote hosts such as Unfuddle or Github – they’ll need a SSH key to authenticate the connection to their servers. Each computer needs a new key, so if you are home, needs one. At work, needs one. At your ex’s house stealing his stuff, needs one. Without it, you can’t get in, simple as that. So let’s get that out of the way first. So let’s do this the easy way without typing much.
Open up Windows 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 “Generate key” (Screenshot). Copy all of that to:
- Github -> Account Settings -> it’ll nag you if you don’t have a SSH key added yet. So add it.
- Unfuddle -> Personal Settings (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)
- For the purpose of learning, I highly recommend using Git Bash – if you learn the commands, you’ll understand how to use Git GUI later. First, go to the folder that you would like to start version control (just use your windows explorer) – then right click on the folder “Git Bash here”. A linux command prompt thingy pops up.
- Create an new repository on Github or Unfuddle
- Github: believe it or not, Github gives you ALL of the instructions you need! So just type what they show you, then you’re good to go!
- Unfuddle: same for unfuddle but they won’t show it to your face. After you’ve created a new repo, click on “Repositories” – you’ll see the new repo you just created, click on it then you’ll see the instructions.
Really, that’s all to it for setting up a new repo server to work with, but for someone who don’t know much about command prompts / shells stuff, it was hard and I’m sure someone else out there had the same problem.
What gives?! Remote hangs???
If you see “Remote hang” – two possibilities:
- 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)
- You’ve entered a password when you created a SSH Key. So if this happens, make sure you leave the password fields empty. If you use Git Bash to generate the key, just hit enter twice when it ask for password. When you’re done, add the SSH-Key back in step 3 – wait a minute a two then try again.
Ignoring Files
Along the path, I’ve asked the same question and it took some diggings to find. If you have a few files you want to do version control, but want to skip files like .DS_Store, .project, .fla or whatever.
Ignore Files Way #1
- During “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 commit yet - Type “git status” – you’ll see a list of “untracked files” – make sure those are the files that you DON’T want to track (version control)
- Then type:
git ls-files -o --exclude-standard >> .gitignoreWhat this does is it will ignore all the files those were showed in “untracked” – then create the .gitignore file for you
- After you’re done: “git add .gitignore” then commit
Ignore Files Way #2:
- Fire up notepad and add the file names that you want to ignore. Example:
.project
.DS_store
whatever.jpg - Save the file inside the same folder where you just initiated a Git and name it ignorefiles.txt (or whatever you want – something simple)
- Open up or switch back to Git Bash – assuming that you didn’t change directory and didn’t close it (otherwise, 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. Otherwise, type the following to change the file name to “.gitignore”:
mv ignorefiles.txt .gitignore
git add .gitignore
git commit -m "Added .gitignore"
You would say why not just change the file extension inside Windows Explorer? Well, go try it, then you’ll see why. I’ll wait……… Done? Worded. As you can see, way #1 is easier. If you did way #1, and want to add more files later, it created the .gitignore automatically for you, so just double 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 wondered was how the heck do I remove one of the files after it got tracked?? Simple:
git rm --cached filename
I’ve seen people tell others to do: git rm filename
That will delete your file for you, too! Did they even read the question?? I prefer removing it then add to the ignore list, I don’t feel safe removing a file physically even though I got Git to watch my back.
Anyways, these are the stuff I’ve ran into when I first trying to setup my workspace, hope this helps. Once you’ve finished this, you’re pretty much up and running. Refer to: http://git-scm.com/documentation for tons of goodies info.