Git: My First Foray

17 Jun

I have recently created a GitHub account and started trying to use version control in my coding – I usually manually make a copy and try new things or overwrite existing code, break it and have to start over. This post will show how to branch a code base using Git. Let me note, Git and GitHub are NOT the same. GitHub is a collaborative online repository and you can push and pull code to and from GitHub with Git.

First, download and install Git.

Create a directory on your machine.

Open a command prompt and change to that directory.

type ‘git init’ to initialize the repository. I added a file code myCode.txt in the directory.

Add all the files by typing ‘git add .’

Then commit them: ‘git commit -m “Some comments”‘

Now you are ready to branch the code!

To see there is only a master branch type ‘git branch’

To add a branch type ‘git branch Branch1’

Change the code and add new files.

Add them ‘git add .’

Then commit: ‘git commit -m “1st Commit of new branch”‘

To see that the master is intact “git checkout master”

open the directory and you should see the original file.

My Master

My Master

My Branch

My Branch


Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s

%d bloggers like this: