GitHub, Creating a Project The Right Way! - Kevin Uriel Fonseca


GitHub

There’s something that I find myself doing every time I create a new project and that is, creating repositories from scratch to push or pull code.

git initgit remote add origin <GITHUB_REPOSITORY_URL>git remote -vgit statusgit checkout -b <NAME_OF_NEW_BRANCH>git branch -d <NAME_OF_BRANCH_TO_DELETE>git add .git commit -m "My first commit"git push origin <NAME_OF_NEW_BRANCH>

Get Everything Ready for our GitHub Repository!

To begin with, everytime we want to transfer a project from our local machine to a remote GitHub repository, we need to initialize a .git file. The command for this task is git init, this file will help us to keep record of every single change we do in our code; these changes range from addition of code up to removal of files. However, this is not enough, we also need the GitHub repository URL to push our code to; the next command will be git remote add origin <GITHUB_REPOSITORY_URL>.

For starters, I could say those two are the very basic commands that every developer should/must know about. In case you need to verify if you have added the proper URL, you need to run the command git remote -v and lastly, to check what branch you are in, run git status which by default should return master.

Don’t Push Unnecessary code to your GitHub Repo!

Every single project runs in X brach but whenever we initialize a project, the default settings are not longer encouraged. This is why we proceed with our following command, git checkout -b main; this command will set our branch to a new one named main or otherwise named as you have instructed it.

With that being said, if you are a solo developer and you’re fully sure that your most recent changes, especially removal of code are not necessary to come back later on in the future, you can delete your previous branch by using git branch -d master; Obviously, deleting branches is a case-by-case scenario, you may/may-not want to have different versions to compare code or to simply have a backup of a very old version of X project.

The very last commands, are going to be the ones you will mostly use. git add . which stages your files up to the most recent changes into your git file. It can be used to stage one single file or every single file; an example to stage one file would be like git add X_FILE; to stage every single file we use the . notation. After that, we can always put a memo to remind us why we did the changes that have been staged; the command for this is git commit -m "Some meaninful comment".

The Final Step, Push Everything to GitHub

Now everything up to this paragraph has been about setting our connection to the proper GitHub repository and staging changes for it to receive but how do we transfer them? well, we use the git push origin main command!. and that will push our code to our GitHub repository in just a matter of seconds.

Bye Bye 🙂

SIDEBAR
FOOTER