GitHub is a web-based Git or version control repository and Internet hosting service. As a developers, I am quite sure that all of you know the platform.
Every-time we start a new project, even if it is just something for us, it is a good idea to use a version control system. Here is where Git and GitHub can help us.
There are two easy ways to create and upload our project to a repository.
The first way, it is to create the repository in GitHub, and after that clone in our machine the created repository and start writing our code. This is the simplest way. Doing it in this way, our local repository is already connected to the remote repository and we just need to start committing things. The clone command, assuming the account name is “fjavierm” and the repository name is “myproject”, is:
git clone https://github.com/fjavierm/myproject.git
Te second way, it is when we already have a project in our local machine and we want to add the project to a repository. In this case, we need to perform a few more steps.
1. We need to create the repository under our GitHub account. In this case, my account is “fjavierm” and my repository is going to be “myproject”.
2. In our local machine, in our local project folder, we need to initiate the git repository. This will add a folder “.git”:
3. We can check the status of the available files:
This instruction will show us the files that we can add to the repository to commit. In this step, it deserves to pay special attention to the files that we do not want to add and, maybe, it is a good idea to create the files “.gitignore” and “README.md”
4. Add the files to the repository:
git add .
5. Commit the added files adding a descriptive message. Usually, issue number and description, or something meaningful.:
git commit -m "Starting the project."
6. Connect our local repository with our remote repository:
git remote add origin https://github.com/fjavierm/myproject.git
7. Check we have perform the previous step properly:
git remote -v
8. Push our changes to the remote repository:
git push -u origin master
With these few instructions we should have available all our code in the GitHub repository.