Adding new Code to your GitHub Repository

来源:互联网 发布:js array slice 编辑:程序博客网 时间:2024/04/28 14:41

http://annasob.wordpress.com/2009/10/18/adding-new-code-to-your-github-repository/


Previously, I posted a tutorial on setting up GitHub and Git Bash. Now I would like to show you how to get new code into ur repository.

Steps:

  1. Create a local Branch
  2. Create a remote Branch
  3. Add files to your local Branch
  4. Commit changes to your local Branch
  5. Push the new branch to GitHub

Those are the steps, now before we get started bookmark this Git cheat sheet its a good reference.

Note: all commands are entered in Git Bash command prompt. How do u open it? On Vista, Start -> Search for Quick->Right click ‘Quick Launch’ result->Select ‘Git Bash Here’

Create a Local Branch

A local branch is a version of your code package saved on your home machine. I believe you can have as many branches as you want.

  1. git branch <branch name>

Create a Remote Branch

A remote branch is one that sits on the GitHub social coding site, users can select this branch and download code that belongs to this branch alone.

  1. git push origin origin:refs/heads/branch name>

The command window will give you a confirmation:

Total 0 (delta 0), reused 0 (delta 0)
To git@github.com:annasob/processing-js.git
* [new branch]      origin/HEAD -> withCursor2-

——————————————————————

Total 0 (delta 0), reused 0 (delta 0)

To git@github.com:annasob/processing-js.git

* [new branch]      origin/HEAD -> withCursor2

——————————————————————

If you get an error saying repository not found make sure your config file is correct. Here is a snippet:

——————————————————————-

[remote "origin"]

fetch = +refs/heads/*:refs/remotes/origin/*

url = git@github.com:annasob/processing-js.git

master

remote = origin

merge = refs/heads/master
——————————————————————

Add files to your local branch

I am not sure if this makes a difference, but i just opened the processing-js directory I was working in and dragged any new files/folders I needed to have.  Alternatively, you can use these commands, well first you have to tell Git which branch you are going to be working with:

  1. git checkout <local branch name>
  2. git add <filename or directory>

Commit changes to your local Branch

Before you can submit the changes to GitHub, you have to commit them on your local machine.

  1. git commit -a

This command will commit all of your changes and allow you to write a message in vim.Vim guide.

The message should be significant, as everyone will read it to see whats new from the previous versions.

Push the new branch to GitHub

Now you are ready to update the remote branch.

  1. git push git@github.com:annasob/processing-js.git<remote branch name>

Note: you will need to put your own repository path in. Here is the message you will see:

——————————————————————–

Counting objects: 7, done.

Delta compression using up to 2 threads.

Compressing objects: 100% (3/3), done.

Writing objects: 100% (5/5), 617 bytes, done.

Total 5 (delta 1), reused 0 (delta 0)

To git@github.com:annasob/processing-js.git

8e069aa..dd33dfd  withCursor -> withCursor

———————————————————————-

After you do all of this, log in to ur GitHub account and go to your repository. If you roll over ‘all branches’ you will see your new branch. Select it and try downloading the contents to ensure that nothing is missing.

Note, I have reported a bug, somehow the download functionality in GitHub doesn’t always work.

Hope this tutorial helps :) Feel free to post comments.


0 0