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.
- Create a local Branch
- Create a remote Branch
- Add files to your local Branch
- Commit changes to your local Branch
- 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.
- 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.
- git push origin origin:refs/heads/branch name>
The command window will give you a confirmation:
Total 0 (delta 0), reused 0 (delta 0)
* [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:
fetch = +refs/heads/*:refs/remotes/origin/*
url = firstname.lastname@example.org:annasob/processing-js.git
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:
- git checkout <local branch name>
- 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.
- 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.
- git push email@example.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)
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.