Showing posts with label Git Tutorial. Show all posts
Showing posts with label Git Tutorial. Show all posts

Updating the Contact List Tutorial

On Wednesday, October 20, 2010 0 comments

Do not attempt this tutorial before I demonstrate on Thursday(10-20-10)

Ok so the task here in this tutorial is to continue to help you get familiar with Git, by actually making changes in the repo. This is assuming you have set up Git already(See here) and that you have an understanding of VIM or have changed the editor to Notepad++(See here).

Disclamer:
As I know someone is going to run into the problem, I thought I would warn you: be sure that your msysgit is INSIDE of your Gravity-Shift folder before trying these commands. This is important because it won't work otherwise.

Okay, the first thing you need to do before you make any changes(to avoid merge conflicts) is to fetch the latest data from MY Git repo. To do this you do this command:

git fetch upstream

This will get all the newest files and changes that the team has made in a whole. At this point, you have these changes locally, but you have not applied it to your own version yet(so if you opened one of the changed files, you would not see any changes). To receive these changes, you must merge the code with this command:

git merge upstream/master

Stop for a second
Why "upstream/master" ? Well, what we are saying is that we want to merge the code from upstream's master branch. If we start using lots of branches(ones for specific bugs, ones for stable releases, etc) this will be important to understand, but for now always do "upstream/master"

We now have the newest code on the computer, which we should now see "ContactList.txt" in the Gravity-Shift folder. Open this and add your contact information into it. Do not forget to save.

The next thing you need to do is commit your changes. Simply do this command:

git commit -a

Which will prompt you for a commit message. This is REQUIRED, and would be best if you do clear messages so that your code is easier to review. The correct format is always "Present Tense" sentences, using words like Add, Remove, and Change instead of Added(Adding), Removed(Removing), and Changed(Changing). Try to be persistent on this format.

After you committed, you need to push your changes.

Alright, woah...
What is the difference between commit and push, and why do I need to do both?

Commit finalizes any local changes on your own local distribution. This means what ever changes you make are official on your own hard drive and that's it. Push, on the other hand, copies those changes into your Github repo(the one online) so that it can be shared with the rest of the team. It is very important to understand that these are separate things, and that committing does not always mean that you need to push as well. You should always commit any changes on a regular basis, but you should only push when you are ready to share with the rest of the team.

So to push your local changes to your online repo, use this command:

git push origin master

Ahh, another weird command
Calm down, we are just saying that we want to push our changes to origin(which is our personal repo's) on its master branch.

VERY LAST STEP!!!!
Go to my repo(See here) and in the upper right corner you will see a button that says "Pull Request" . Press this button, and fill in the popup box with your changes(same format as commit messages) and send it off. I will then be able to take your code and merge it into the main repo so everyone can receive the changes.

VIM text editor instructions

On 1 comments

So, while using msysgit, you will more than likely end up using VIM to write text at least once(unless you change it, which I will tell you how to do that at the end of this tutorial). A good example of when VIM is required is during a commit. The editor is extremely difficult to understand, especially without any instructions, which is exactly what this tutorial is for.

Lets make an assumption that I just made some change to the code; how bout I added the ability for the player to change colors. Once I had the job finished, I would commit:

git commit -a

This would immediately start the text editor, VIM. It would have a print out something like this:

(Your cursor should be here)
#############################
# You made a change that needs to be committed
# The following files have been changed
# (To reset to head, use git reset HEAD)
# WindowsGame1/Player.cs
@
~
~
~

Or something like this at least. Your cursor should be at the very top, if its not, you'll need to move it using the arrow keys.

1. Press the letter i to enter Insert Mode.

2. Type your message: Add player ability to change his color

3. Press the Escape key to exit Insert Mode

4. We now want to save. Type :w (do not forget the : in front of the w) and press enter

5. To exit VIM, type :q (do not forget the : in front of the q) and press enter

Your file will then report to git that you are done writing the commit message and are now ready to commit.

As a final reference, to start VIM with a file(it will be a new file if it doesn't exist yet) type this command:

vi

To difficult?
Yeah I agree, that's why I went in search of a different solution, which I will share with you. Be sure you have dowloaded Notepad++(found here) and type this command in msysgit:

git config --global core.editor "'C:/Program Files (x86)/Notepad++/notepad++.exe' multiInst -notabbar -nosession -noPlugin"

So the git config --global core.editor tells git you want to change the text editor. The 'C:/Program Files (x86)/Notepad++/notepad++.exe' is the location of Notepad++ so it might be different for you. You will have to browse your computer for the Notepad++.exe.

Git Instructions for the team

On Wednesday, October 6, 2010 0 comments

Also, just a note(I'll probably bring this up thursday), as just users of the git repo, this should be your process for setting up(using a command line git program):

Step 0: Create a Github account

You need a github account before you can do anything. Go to github.com to get it

Step 1
: Set up your SSH keys

You'll be pulling your hair out if you miss this step. Be sure to read it carefully. This is assuming you are using msysgit(which I still recommend for the cs people)
http://help.github.com/msysgit-key-setup/

Step 2
: Fork Project

Forking the project is pretty easy. Go to http://github.com/DizWARE/Gravity-Shift/ and click the "Fork" button near the top on the right side

Step 3: Clone Repo

git clone git@github.com:
(Your Github Username)/Gravity-Shift.git

This will automatically add this git repo to as your remote upstream/downstream, under the alias "origin"

Step 4: Add the original repo for fetching the newest updates

cd Gravity-Shift
git remote add upstream git://github.com/DizWARE/Gravity-Shift.git
git fetch upstream


This will add the main git repo for global updates, under the alias "upstream"

At this point, you should not have to do the Steps 1 - 4 ever again(unless something happens). From here on out should be your update cycle for anytime you make any changes.

Step 5
: Make modifications

Adding/removing code or any files(images and such) will do this

Step 6: Committing your changes

git commit [Filename/s]
to commit one or more file

or

git commit -a
to commit all files

This will immediately start the default text editor(usually 'vi') to add a commit message.
Always, always, always fill out your commit messages, so that when you try to update your code on the main repo.
These commit messages should all be in present tense(important) and should start with a brief description on what is changed, and then a list of all changes. Here's an example after I added the ability jump in the physics engine, and the controls for it in the control scheme(hypothetical):

Add the ability to jump in the game
-Add the physics definitions for jumping in the physics engine
-Add the controls for jumping in the control schemes

Step 7: Push updates up to your fork

git push origin
(branch name)

(branch name) is usually master if you have not created and checked out a different branch. So basically, if you don't know, use 'master'

Step 8: Sharing your updates with everyone

In github, go to http://github.com/(Your Github Username)/Gravity-Shift.git and click the "Pull Request" button in the upper right hand corner

Step 9: Getting peoples updates from git

git fetch upstream
git merge upstream/master


Lastly, for those who are still doubting on the WHY of git, take a look at this video of Linus(inventor of git, and also the inventor of Linux): http://www.youtube.com/watch?v=4XpnKHJAok8
Skip ahead a bit, because he gets into the details near the end.

Powered by Blogger