DEV Community

Cover image for All about Git Command Lines.
Yahaya Kehinde
Yahaya Kehinde

Posted on • Edited on

All about Git Command Lines.

Git is an open source distributed version control system commonly used in software development and basically tracks changes to source code. It allows full access to every file, branch or changes to a project, and allows every user access to a full and self-contained history of all changes and as such developers can work anywhere and collaborate asynchronously.

Git allows us to identify :
1) Which changes were made to a project?
2) Who made those changes?
3) When the changes were made?
4) Why the changes were required?

In this article, we are going to be discussing how to push your files from your computer to the github server using the command lines on your terminal.

Now in order to use the Git command lines, let's assume we have a new folder on our desktop named newTask that contains three files index.html, style.css and script.js. In oder to use the command line to upload this folder from our local machine to the github sever, let's follow the following simple steps.

1) First we open up the terminal and navigate to the current directory where our files are using cd <name of directory>.

2) Next we use the command git init which creates a new git repository locally on our computer.

3) To confirm the exact files within the current directory, we use the command ls which will reveal the three files we currently have in the newTask folder.

4) Afterwards, we add all the files to our newly created repository using git add .

5) The next step is to send all the files to the newly created repository, by using git commit -m "Adding my first commit"

Now let us assume we made some modification to our script.js file. In order to confirm these modifications, we use the command line git status. This will bring in red text the files which were altered. However we need to add these modified files again back into the repository.

So we add the the altered file using git add script.js ,and check the status again using git status. This time it brings out the altered file in green text indicating that it is ready for the next commit. Lastly we the re-commit it using git commit -m "altered script.js". At this point, git status shows "nothing to commit".

There is a unique way in git to get all the previous versions of a project both before and after modifications were made using the command git log. This shows all the commits and gives then a unique key/code that enables us to switch between current and previous versions of a project. Therfore with these unique names it's also possible to find out the exact changes between two commits by using:
git diff <uniquecode in commit-1> <uniquecode in commit-2>

Now we can easily travel back in time to an older version of the project in commit1 before changes were made, with this unique code git checkout <uniquecode in commit-1>.

Finally to add our repository online to git hub, we create a new repository in our server, copy the url and use the command

git remote add origin <url>
then git push -u origin master

In summary Git lets developers see the entire timeline of their changes, decisions, and progression of any project in one place. From the moment they access the history of a project, the developer has all the context they need to understand it and start contributing to projetcs.

Top comments (0)