GIT AND GITHUB FUNDAMENTALS - BASIC GIT OPERATIONS

GIT AND GITHUB FUNDAMENTALS - BASIC GIT OPERATIONS

GIT AND GITHUB FUNDAMENTALS - BASIC GIT OPERATIONS

GIT AND GITHUB FUNDAMENTALS - BASIC GIT OPERATIONS

In the previous articles we have looked at Git, the command line and usage with Github. It is also important that one notices that they are all similar and work together to enable good developer workflow.

We also looked at some differences between the command line and a graphic user interface, the advantages and disadvantages of the two for developers. The command line may seem overwhelming at first for developers because of its boring interface and lack of interactivity, but it gets better with practice.

The previous article before this one covered basic file operations on the command line with a text editor, from creating files, to editing them and saving them all on your local machine.

In today's article we are going to focus on one basic git operation for developers when working on computers or with Github generally. Lets us look at everything you will gain from this article

TOPICS

  1. File hierarchy, understanding how to change directories properly
  2. Cloning repositories from Github
  3. Adding files to repositories
  4. Commiting files to be saved on repositories
  5. Pushing files to repositories

FILE HIERARCHY - UNDERSTANDING HOW TO CHANGE DIRECTORIES

Hierarchy as a word means a system in which members of an organization or society are ranked according to relative status or authority. In the same way file hierarchy simply means ranking files from the parent to the child. A parent file is on that contains the child file, while the child file is contained in the parent file.

The real reason you have to understand file hierarchy is because you need it to navigate the command line effectively. On the command line you cannot change a directory to another which is not present in the parent directory.

Example:

Let's say you change directory your desktop using “cd”

cd desktop

Then remember to “ls” in order to find out where you are

ls

Imagine you have directory/folder called “coding_bootcamp” on your desktop with the file “main.js” in it.”/desktop/coding_bootcamp/main.js

Then another directory/folder on your desktop called “java_1” with the file “spring” in it. ”/desktop/java_1/spring”

Suppose you change directory “cd” into the “coding_bootcamp” where the “main.js” file is but you quickly remembered you need the “spring” file in the “java_1” directory.

The logical thing to do would be to change directory to “java_1” right, but then you “cd” into “java_1” and it says the file cannot be found.

cd java_1

This is because you are not following the proper file hierarchy, in the actual sense you are meant to go change directory back to the desktop then locate the file before you can change directories into the “java_1” directory.

cd desktop

 When inside the “java_1” directory you only have access to the “spring” because the “java_1” directory is the parent to the “spring” and that is all. In this same way while in the  “coding_bootcamp” directory you only have access to the “main.js” file .

The main point is that you only have access to children files for any directory you are currently in, and to access another directory you have to “cd” and go back or forward into the parent to locate the file.

From the coding panel you should be following and understanding the file hierarchy and how it affects navigation through files.

CLONING REPOSITORIES FROM GITHUB

Cloning a repository from Github is one of the first things you should be able to do as a user. I basically mean downloading an existing directory to your computer in order to make changes to the files present in the directory. We covered this part in our previous article but more practice is needed if a beginner truly wants to master Github. 

  1. To clone a repository from Github, you need to have an account on Github checkout this guide for more information
  2. Create a repository by clicking the “new” button and make sure to name the repository whatever you wish.
  3. The next step is to copy the clone line by clicking the green button at the top right corner of the repository, copy the link there and go to your Git Bash.
  4. Change the directory to where you want the repository to be, I will choose the desktop.
    cd desktop

  1. Clone the repository with the following command “git clone”.
    git clone https://github.com/NwabuezeFranklin/alx-low_level_programming.git

  1. You have successfully cloned the repository on your desktop and can now make changes to it.

ADDING , COMMITTING AND PUSHING FILES TO GITHUB

When you clone a repository on Github and are done with making changes, it is normal to add the files back, then save/commit them and push to Github.

Let us assume that our repository name is “Build_with_mel” and we have two files in it called “main.js” and “spring.js” , here is what we have to do to add, commit and push.



  1. Change directory into the repository and add all the files individually to the repository
    git add main.js
    git add spring.js



  1. Adding all the files individually is possible with few files but very tedious with multiple files but thankfully there is a way. Us eht command “git add .” to all files at once no matter the number
    git add .

  1. To commit use the following syntax “git commit -m “a message about the files you worked on””. This commit message enables you or anyone to understand the work incae of collaborations in the future.
    git commit -m "commit message"



  1. To push all you have to do is to type the command “git push” and all files in your repository will be updated remotely.
    git push



With this you have concluded and mastered the basic git and github commands, remember to always practice and keep improving your skills  all the time. More articles like this one will be released guiding you on more concepts.

Don't worry if you dont know all the commands yet or if they aren't quite sticking in your memory yet. They will soon be seared into your brain as you use them over and over in future projects.

In later Git lessons we will cover some of the advanced git features such as branches. They will further expand your abilities and make you more productive.

For now concentrate on the basics and soon you will know all the Git commands from memory and use them seamlessly in your projects. Keep working hard and see you in the next one!!



What's Your Reaction?

like

dislike

love

funny

angry

sad

wow