Git

Git 101 – Introduction to Git

Getting Started with Windows

Download msysgit – Essential
http://code.google.com/p/msysgit/downloads/list

You should use Git-1.7.0.2-preview20100309.exe
Not tested 1.7.1 cos it’s contributors only. But

Download SmartGit – Optional but best git interface I’ve found
http://www.syntevo.com/smartgit/download.html

msysgit comes with Git, Git Bash, Git GUI and more. Git Bash is essential to getting your hands dirty. It’s a linux-based shell (will look for the appropriate term) so all your favorite shell commands are available including SSH, cp, etc.
Getting Started with Linux

SuSE Linux 11.1

# yast --install git

The above should do it. If there are issues, then you probably need to enable your online repos.

SmartGit also works on linux so you should get it

Ubuntu

sudo apt-get -y install git-core gitosis

Git Clone
As the name implies, it creates a clone of an existing given repository.

You can try it out by launching Git Bash or your favorite linux terminal.

# git clone <repo_url>

One lovely thing about git is that the flexibility of <repo_url>. Git supports a wide range of protocols including ssh, git, http, ftp, local filesystem, etc. This means you can clone just about any git repo once you have access.

Git Init
This is for creating a new repo. e.g. on your local system.

# mkdir <my_repo>
 # cd <my_repo>
 # git init

Git Add & Commit
At this point I’m assuming you have a repo to work with and you’ve updated or added some files. So you want to update your repository with the changes you’ve made. So where do you start?

First thing you want to do is stage your changes. What staging means is telling git which files you want to commit.

# git add <file>
 # git add . (all files)
 # git add *.ctp

This is great if you want to commit just a few files. Staging is for both versioned (files already in repo) and unversioned files (files not added to repo).

After staging, you can then commit your files.

# git commit -m "<Description of Changes>"

This records your changes to your local repository. Now you can code some more.

Git Remote, Push & Pull
Now that you have committed your changes to your local repository, they won’t do you much good until you have updated your central repo/site. And thats what remote, push, pull are form.

Remotes are other copies of your repo. They may be local or online, or on your local server. Git supports more than one remote which is another lovely thing about it.

Lets assume you cloned your repo. This means you already have your remote set (its called origin). To check your remotes

# git remote -v

So how do you send your changes to your remote server?

# git push origin master
 # git push

So how do you get changes others have uploaded to your server?

# git pull origin master
# git pull

Note that origin is the name of your remote and master is your branch.

If you started your git repo from scratch (git init), then you don’t have a remote setup. To add your origin remote

# git remote add origin git@github.com/projectone/komplaints.git

Git Branches and Tags
Please read ProGit. A summary won’t do it justice especially cos u’re already have an idea about branches and tags.

Git Submodule
At a point, you may want to have a repo in a repo. Thats where Git Submodule comes in. For example, you what to add debug kit to your cakephp project.

Lots of people hate submodule cos u of some extra work it adds if you update your plugins regularly. Note that it is absolutely essential you understand the pitfalls of submodule before using it otherwise you’ll … urhhh … end up in a pit.

Ignoring Files
There are two main scenarios where you’ll like to ignore files. First scenarios is when you have files that are inevitably in the project directory but are not part of the project. e.g Temporary files, cache, session files, IDE config files etc. These are files that you don’t want to add to the project at all. To achieve this you can use a file which should be in the root of your project .gitignore. It should contain a list of files and directories that you what ignored.

NOTE that this does not affect versioned files. If you what to ignore versioned files, you’ll have to remove the file from the project first before git will ignore it.

# git rm <file>

The second case is a file does belong to the project but you don’t want git to notice changes to the file at all. For example, in CakePHP, app/config/core.php and app/config/database.php are two very essential files but if you commit your local copy of these files to your main repository/production server you’ll most likely get angry calls real soon from your team-mates or clients. The solution is simple

# git --update-index assume-unchanged <filename>

This totally ignores changes to these files. So if you all commit and push all changed files, the files you’ve applied this to will be ignored.😀

Standard

6 thoughts on “Git 101 – Introduction to Git

  1. the big bang theory free streaming says:

    Hi. AMAZING POST! Oh btw, sometimes your websites looks funny on this browser, I’m on my linux machine right now.

  2. conquer online cheats says:

    This is a great post. Something I’d like to mention is that your website sometimes isn’t displayed correctly on my browser…

  3. Pingback: “I’m dead! All my data gone!” | t(h)inker's thots

  4. Pingback: “I’m dead! All my data gone!” | t(h)inker's thots

  5. Pingback: Getting started with Git and Windows | Nardax

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s