Mastering GitHub: Step-by-Step Tutorial for Uploading Code via Linux Command Line.

Working with code can quickly become very difficult, especially when it comes to big scale projects. Not only does the modules themselves take up storage space on the system but it is also very difficult to share them amongst team members and the masses. This task is made significantly easier by using Git and GitHub. 

What is GitHub?

GitHub is an online platform and cloud based service owned by Microsoft used mainly for software development and code sharing, over the years it has gained more and more popularity amongst developers and enthusiast alike.

What is Git?

Git is a distributed version control system that track changes in any set of computer file.

Now, that sounds very interesting, but how do you make commits and upload your code on the platform?

In this step-by-step guide, i will show you how to upload your project files and code via the Linux terminal to GitHub using Git.

Firstly, After launching Linux, head to your root terminal and install Git by using the command "sudo apt install git".



Now that Git has successfully been installed, go ahead and check the version by using the command git --version . This ensure that the most recent version of Git has been installed correctly.

Secondly, now that Git has been installed, we can go ahead and configure Git.
Using the command git --global user.name "Your username"

Using the command git--global user.email "Your email" .
Thirdly, select a directory or create a new one.
Personally i created a new one as i was using a brand new virtual machine.

Using cd basic-c++ to switch to the directory, then using the command git init , to create a new Git repository.

Using the command git status we can see that there is no commit yet but there is in-fact a file present in the directory.

Fourthly, we need to add the file that we want to commit. Using the command git add <filename>.

Now,that we have added a file, when checking status we should see the filename have turned green.
Using the command git commit -m "Message"

After signing into your GitHub account, go to the "create new "button.


Give the repository a meaningful name and click the create repository button 

We do not need to create a new repository on command line as we already have the files present on our machine, so we go to the second option push an existing repository.
Copy the first command and paste it in your terminal.

If you try using git push -u origin master you will not be able to upload your code as password authentication is no longer supported.
What you now need to do is :
1.Go to settings.
2.Go to Developer setting.
3.Go to Personal access token.

Choose an option and click generate.

Give your token a name and change the expiration date .

Click all the boxes and click the button named generate token.
 
You should see something similar to this.

Copy your token and paste it in a safe place as you only get access to i only once.
 
Use the command git remote set-url origin https://<token>@github.com/<username>/<repository>
Finally, you can use the command git push -u origin master.

Refresh your GitHub page and your project should be there.



Comments