Getting started with GitHub can be torture unless you come from a Linux background. I hated it so much because I was so use to getting programs with user interface so the last thing I wanted to look at was a terminal or a command prompt. I started to use the GitHub application but I was creating problems for my team mates and even that can be confusing. Most of the stuff online about Git is very dense and makes it hard to get started. I did find a great website for some simple commands after digging through all the advance material out there.
After learning a handful of commands it really is not that bad. If you are new to Github then most likely you will just need to know a handful of commands to get by and just let the more experience guys do the rest. I will assume that you already did the setting up Github by downloading it and configuring it. You will also need to set up an account.
Cloning a Github Repository
Sometimes you may need to only clone a Github repository if you are not going to contribute to a project on git. This is also a starting point if you are coming onto to a team with a repository already setup.
Here is the steps:
- Open the Terminal/ Command Prompt
- Create a directory(i.e ‘mkdir foldername‘)
- Go to that directory (i.e ‘cd foldername‘)
- Add git to it (i.e. ‘git init‘)
- Add project in the directory by cloning a repository with the ‘git clone command url ‘(git clone https://github.com/nicolasgramlich/AndEngine.git)
To get the link to clone the site visit the link where the repository is at and there will be a HTTPS clone link on the page. Here is a screen shot of what I am talking about.
Here is the full example screen shot to clone a repository.
Contributing to a Github Repository
I like to look at this as a 2 part process. You need to do a pull request which is updating your local project with what is on the repository. This will not erase your changes but just merges the changes. Then after you do a pull then you can do a push.
Pull request for Github
Like I said this is updating your local project with what is on the online repository.
- Make sure you are in the right folder inside the terminal/command prompt ( use the command ‘cd’ to move between folders i.e cd myproject , or just ‘cd’ to start over).
- Add your files with the ‘git add . ‘ command ( the ‘.’ will add everything but you can you specify the folder here if you like)
- Commit your changes and add a message with the ‘git commit -m ‘message‘
- Pull with the ‘git pull’ command ( you may also need to add the url to the repository that you use earlier for the cloning).
Your folder is now updated.
Push to a Github repository
This will update the online repository with what you have in your local directory.
- After committing and pulling.
- Use the ‘git push‘ command.
You will want to switch branch if you want to pull and push to a particular branch on a particular online repository.
- Inside the terminal make sure you are in the right folder with the ‘cd’ command (i.e cd foldername or use ‘cd’ to start over)
- Use ‘git checkout branchname‘
More to come and screen shots ….