Create a Git repository on Github and upload the code

Explanations about the process of creating a new Git repository and how to upload the code to a repository created on Github.

In this article we are going to address a basic day-to-day operation of the developer and work with the Git version control system. Basically we will explain the steps to create a new repository on Github with the code of a project.

This article is motivated by a question answered by a fellow community member who had questions about the version control system. The question was the following:

I have been asked to upload a project, the code, to Github in a new repository that I have to create. My problem is that I am not familiar with this operation and for fear of appearing inexperienced I prefer to ask you. I imagine that this is done with Git, but I don’t really know how to do it… if I have to make it public, private, if I upload the zip or how I do it so that the code appears on Github.

Our answer comes next, explaining the entire operation step by step. Anyway, this answer would be much clearer if you take a look at the , or the one that is much more advanced.

Create a repository on Github

I really do not know very well at what point in the process you have the doubt, but it seems a bit general of the use of Git, so I will explain in a few words how you should do it.

From Github you create a repository with the “+” button on the top right. Obviously you have to have signed up for Github to get started. Registration is free.

See also  CSS Workshop

You appear on a page for you to indicate the repository data. Basically you have to give it a name, choose whether it is public or private and optionally a description. I always leave the part that says “Initialize this repository with a README” unchecked. Later I will comment something more on the “README”.

The issue of making the repository public or private has to be told by those who have asked you to carry out this task. If I’m not mistaken, to make repositories private you must have a paid Github account, so I understand that they will have asked you to make it public. You will have to clear doubts with them

Once you create the repository, keep the page that appears on Github in the browser for now, because it has important information that we will use immediately.

Upload the project to Github with Push

Do you know what you have to do to upload the files? It is easy. You don’t upload it by Zip or anything like that, but you use Git itself, the version control system. The operation you have to perform is called “push”.

I do it from the command line, but there are graphical interface programs that also make these steps perhaps easier. If you don’t have Git installed, you’ll first need to see how to do it (download an executable and install it) in this article: .

Note: Keep in mind that if you are on Linux or Mac you will use the terminal of the operating system itself, but if you are on Windows you will use “Git Bash” which is the command line terminal that is installed when you install Git, which is much better. than the basic terminal that comes with Windows. The command to move between folders is “cd” followed by the name of the folder where you want to go.

See also  Set a start value in an autoincrementing field

Once you have Git installed, you have to go, in the terminal, to your project folder, then there you generate your repository locally with the “init” command (if you haven’t already done so).

git init

Then, from the folder you do the “add” command to add all the files to the “staging area”.

git add .

Then you issue the commit command, which pushes the files to the repository for change tracking. It is the following:

git commit -m ‘my first commit’

Instead of ‘my first commit’ put something that is less generic and more relevant, related to your project and the state you are in 😉

Then you have to “push” from your local to remote repository with the commands that appear on the Github page right after you created the repository (where I asked you to stay with the browser). Go back to your browser and you will see them, at the bottom, in the option to upload an existing local repository.

It’s something like this:

git remote add origin https://github.com/here-your-repo.git

And then you do the push itself with git as well:

git push -u origin master

I insist that these two commands appear right on the page you arrive at when creating a repository. It’s good to copy and paste from there, because the URL of your repository will appear on GitHub and you don’t risk typing wrong.

Recommended additional steps in operating with Git

To finish, or before uploading the project with push, for best practices, you should put a README.md in your project (you generate the file locally and do git add . to add it and then commit).

See also  Knowing Sublime Text 2

That README.md file has Markdown syntax, which allows you to write things like links, headings, bold, etc.

Then it’s also good to have a , which we can talk about later, but it basically causes Git to ignore certain folders or files that shouldn’t be pushed to version control.

I think that’s all. Surely I have clarified several points for you. Try it and fight a bit, that’s how you learn. This operation may seem complicated at first, but when you do it a few times things become clearer.

Loading Facebook Comments ...
Loading Disqus Comments ...