Skip to content
Schmoozerd edited this page Oct 6, 2011 · 3 revisions

First Part

This part should introduce you to adding a new branch with Git, switching between the branches, and how to do the most basic work with Git.

The changes for the ICC learning project are currently located at SD2 repository, within the branch "icc_project"

This part assumes:

  • You have already cloned SD2, if not look into http://www.scriptdev2.com/showthread.php?t=4

  • You are on a clean branch, and have not yet used the name "icc_project" for a branch on your system. See the next section how to check, and restore a clean environment

I will always use the Git bash to work with Git. Hence I strongly suggest for you to use it as well. But nearly all stuff must work with GUI tools somehow (Note for *nix User: "Open 'Git bash here'" can be translated to open a bash in the directory)

So, to do anything with Git, we will open a Git bash in the ScriptDev2 directory in your MaNGOS source folder - in src\bindings\.

To do so, open your explorer, right click the "ScriptDev2" directory and select "Git bash here" from the context menu.

This will open a nice black and white window, where you can type commands in a very old fashioned way :)

Checking your status

The first and most important command is

git status

This will show the current state of your work tree related to the index.

What does this mean: When you look at your ScriptDev2 directory, there are two things you must keep in mind:

  • The directory contains files - these files are referred to as the work tree, and are just normal files.

  • Git has an internal representation of the history related to your project, this history is stored in the index.

So git status now shows you in which state every file in your work tree is in relation to what state the file should be compared to your current history index

The default output should be:

# On branch master
nothing to commit (working directory clean)

This shows you that you are on your "master" branch (this is default), and that you have no change related to your history (working directory clean)

Exercise
Exercise 1 - Check the status

Add or change a file, and compare the output of git status

If you have a not clean working tree, you must clean it.

Resetting your working tree to the index

Warning

This will delete all changes!

git reset --hard

Note: This will only affect files which are known to the index, so a new created file won’t get deleted.

Remark: This will only give you what I expect, if you didn’t too many experiments yourself.

Updating your remote information for the SD2 repo.

The SD2 repo (assuming it was cloned from initially) should be named "origin" If you have done nothing special, it will be and you don’t have to worry.

To update the information for the remote origin repository, simply do:

git fetch

Cloning the remote branch containing the icc learning project.

Git is really great when it comes to branching. This means, it is easy to have different branches of history-indexes and to switch the working-tree files between them.

The reason why branches are so cool is, that one branch does not change the history of another branch. So it is very easy to have different things to work on.

The process to switch the working tree from one history branch to another is called "checkout", and hence the command that is to be used is

git checkout <newBranch>

where <newBranch> is the name of the branch to which you will switch your working tree

However, before you are able to checkout to a branch, you must create it.

To make this easier, there is the "-b" option for the checkout command:

All in all you should type:

git checkout -b icc_project -t remotes/origin/icc_project

This will do the following:

-b

create a new branch named "icc_project"

-t

use the point from which you branch as "tracking" branch

remotes/origin/icc_project

is the branch icc_project in the repository origin which is a remote repository

Switching between branches:

As already mentioned, you can easily switch between branches with

git checkout <branchName>
Exercise
Exercise 2 - Test switching

Observe changes of files in the directory (especially the sub directory icc_project) while switching with

git checkout master
git checkout icc_project

End of First Part

What this part was about:

  • Checking the status of working tree, command > git status

  • Checking out a remote branch into a local branch

  • Switching branches, command > git checkout

Most important concepts:

  • index and working tree (What were they?)

  • branches in Git (What are they used for?)

Additional resources:

Tip
Tech talk about what Git is not This is a nice vid, it should clarify why we use git, and explain some more concepts of Git :)

What comes next:

  • How to do local commits

  • How to read history

Clone this wiki locally