Using Git in your Works

My GitHub activity Now that I've been using GitHub for more than 6 months for almost all of my personal (and some commisioned) projects, I think I feel comfortable enough to explain the Git basics and why it simplifies a lot of things if you are a developer.

Features

I wouldn't expect you to move to Git if I only explained how it works (there are several hundred guides around), so I'm going to give you some of the improvements it made to my development life:

  • On September, I moved to New York and I couldn't bring my Desktop PC with me. I needed a PC to work so I bought an Asus laptop. Because I had being using GitHub to save all my projects, I could easily import all the projects with some commands that I will tell you later.
  • GitHub also serves as a backup for all your code. If your PC goes in fire, you will still have your code saved in GitHub's servers (but you will have to expend some money on a new PC :dollar:).
  • Collaboration is the key. If you have some public projects, you can let people collaborate with you. You don't expect people to fix issues and add features for you if your code isn't public or shareable, and that's one fundamental feature of Git.
  • Free if you are an student: I didn't wanted to pay for a GitHub account at first (I would right now), but when I heard that they give free licenses to students I just rushed to get an account. You can get yours here.

Creating your first repo

It doesn't matter if you have a free or a premium account, you can create as many public repositories as you wish. You can create them by clicking the "Plus" symbol in the top and adding all the details: GitHub repo creation page

Once you are done, you need to copy the link provided and go to your favourite IDE or console and use this commands

{% highlight bash %}

Creates a git repository in the folder you currently are

git init

Sets the online repo to your recently created GitHub repo

git remote add origin

Add all the files to git. You may want to add files you don't want to a .gitignore file

git add . {% endhighlight %}

Uploading your changes

You can now start working as you would normally! Whenever you think you need to upload all your changes use:

{% highlight bash %}

(OPTIONAL) Add newly created files

git add .

Commit your changes to the local repo. NOTE: Use the -S argument if you would like to sign your commits

git commit -m 'Your commit message'

Pushes your commits to GitHub (branch master). The -u argument saves your selection and you can later use git push only

git push -u origin master {% endhighlight %}

That's it! You now have your code backed up online available to all the developer community (if your repo is public).

Additional things you get

GitHub project navbar

GitHub isn't only about files full of code, you also get Issues management where you can file all your nasty bugs and have a thread for each one, Pull requests, that are the way for others to make changes to your code and much more! GitHub also offers an API that for example, I have already integrated with the Lab page, where you can see all the latest commits for all my public projects.

You can see all the cool features you get at https://github.com/features.

Summary

I hope you liked the way I currently work and you start using it in your own projects. GitHub is the easiest way to go to backup your code online although there are other alternatives such as GitLab and BitBucket.

Today, we learnt how to create our first repository and how to push your changes online. You can contact me via [Twitter]({{ site.data.social.twitter }}) or [Email]({{ site.data.social.email }}) if you still have some doubts.

Hugo :wink:

© Hugmanrique. Made with