Simple Git tools using a Command Line Interface

Here is a simple guide on how to add files from your device onto a GitHub repository for your and other collaborators' ease of access.

Step 1
The first step is to configurate your personal info on Git in your device so as to match those of your GitHub account.

On the CLI, type the command;

git config -- global user.name  "Your name" ; git config -- global user.email " Your email "




Step 2:
Go to your GitHub account on a web browser and create a new Repository.
Do so by clicking on your account > Repositories > New
Be sure to give it an appropriate name so that collaborators may be able to identify it quickly.

I will be uploading the answers to my CS University course's labsheets, hence I will be making a repo named "programming_labsheets".


Step 3:
Afterwards, you will be redirected to a page with detailed instructions on how to proceed with uploading the files. 



Before we continue:
Note that these commands will prompt you to input your GitHub account credentials, however support for input the password was discontinued.
Instead, you will need to generate a token and paste it when prompted to input your password.
[https://github.com/settings/tokens?type=beta]

The password itself will be hidden and you will need to make sure to paste it once and hit Enter to proceed with the push.

Step 4:
Navigate to the directory where your files are located on your device.



Continuing with my example, here are the labsheet files located on my device.

I will also take the opportunity to add a README text file in the directory using the 'echo' command so as to explain the contents of and anything important related to the files I'll be uploading.
Disregard the fact that I'm overwriting a previous README file as it is a leftover from a previous attempt.

Note that you can, at any time, use the command 'git status', to find the branch you are currently working on as well as any changes pending to be commited.

Use git commit - m "message" to commit to the changes and add a comment.

Make sure you are on the correct branch before proceeding. Use git branch -m branch name to rename the branch. By default the branch name is 'master' on the CLI while it is 'main' on GitHub.

Then, I will use the command 'git init' in order to initialize the repository.



Step 5:
Now we can add all the contents of our directory to our repository using the 'add .' command.
And once more, use the 'git status' command to gain an overview of the pending changes and the currently used branch.



Step 6:
Next, we will have to establish a connection between our local repository to our online repository.
Find the URL to the repository you create on a web browser and then input this command;

git remote add origin link to the repository


Step 7:
Now we can push the changes.
Use the command;

git push -u origin branchname

Finally input your username exactly as per your GitHub account and paste the previously generated token instead of your password.


And now you're golden!
Be sure to check if the repository has had the changes pushed by visiting the webpage.




Extra: Cloning a repository
Access the desired repository on a web browser and click on Fork.
This will create a copy of the repository to your account.
Then access the forked copy of the repository on your account, click on the <>Code drop-down menu and copy the URL of the repository.

In this example, I will clone the repository of first-contributions.

I will start by making a directory on my device named "first_contributions" to do my work.

Use the following command to clone the repository;

git clone URL of the forked depository



You should now have access to the repository on your device.

First-contributions provides you with a text file that let's you add your own name into it.


Afterwards, you may proceed using the previously shown steps as you see fit. Remember to create new branches in order to sort out the work in an appropriate fashion.

git switch -c new branch name is used to create a new branch

The second git status displays changes to the file as the command was written after I have added my details to the Contributors.md




Finally, I add the changed Contributors.md to the repository using git add the file
and a small comment with the aforementioned git commit -m command

Finalize the changes by using the push command and inputting the account details as shown in Step 7





Comments

Popular posts from this blog

NetBSD

How to install a virtual machine [A step-by-step guide]