Git & GitHub

About git and its use for newbies

Kavindu Gayantha
6 min readMar 17, 2020
git + GitHub

Git is a tool that every programmer should know. If you are new to word git, read this article until the end.😀

Git is used for version control. It can be used in software development for tracking changes in source code. It is very useful when we are developing a big program. Always there is a probability in software development to be crashed a software that we are developing. We can avoid that risk when using Git. That development under git control we can do it as several versions. If we went wrong in any version we can go to the previous version that works successfully and can continue our works. And also git is used for collaborative development. We can use git by dividing it into several branches and do changes in code. That affects only that relevant branch not to the main ( master ) branch. If something went wrong, that only affect that branch. It doesn’t matter we can delete any branch in any time and continue our works. Let’s see further how to get started working with Git and how these things happen.

Follow this link to download git to your computer.

https://git-scm.com/downloads

Actually, I am using Linux. So I will show you git bash commands from this article.

$ sudo apt-get install git
type in the terminal

now check the version of git. if it is shown any version like this, git is installed successfully.

$ git --version
check git version

before working with git we have to configure git. To configure git use these commands.

$ git config --global user.name "username here"
git config username

this user name is the name that you use as your user name in git commits.

$ git config --global user.email "your used email here"

this email is used as your email for git commits

configuration git

Now you are ready to use git. Let’s go through it.

When you use git another name is come to our mind ‘GitHub’. Actually GitHub is a service that use to host projects that use git, then others can see our source code, and they could be suggest changes and can make a request to edit the source code of our existing code. That is how major open source projects are built.

here some open source GitHub repositories

To use GitHub you should be having a GitHub account. refer this link to make a GitHub account.

create github account

sign up with credentials. Then you are ready to use GitHub. : )

In GitHub all are made with repositories. You have to make repositories for each your projects. One repository for one project. Let’s see how to make a new GitHub repository.

In the GitHub page in the navigation bar click the icon of your profile pic that placed right corner. Then there is a drop-down menu appears.

select your repositories.

drop down menu

now click new button

new button

Then input repository name and a description as you wish. And create repository.

you can make the repository in public or private

private repositories are not visible to others but public is. However you can make changes in repository type as make public or make private. ;-)

Now you can see the page like this

my-repo new repository
simple diagram to explain Git and GitHub mechanism

Now let’s make a git repository locally. When we push our code to GitHub we should made it locally in a git repository. Let’s see how to do that.

Go to any directory in your computer as you wish to save your git project.And type below command to realize whether it is a git repository or not,

$ git status
if it is not a git repository, this message will show

then make that repository as a git repository, type this code

$ git init

now that repository is a git repository.

initialize a git repository

now make some changes in this repository.( you can start your project here now ).

made a text file and see what changes
$ git status

this command shows all git changes from last git commit.Now push this changes to git, follow these commands if this is the first git commit of this repository.

  1. git add
  2. git commit -m “ commit name ”
  3. git remote add origin < paste git cloned url here >
  4. git push origin master
1).$ git add .

this means, add all git changes in this repository to git. dot sign(. ) says ‘all’

if we want , we can add file by file to git after naming which to add to git

$ git add <filename here>
add textfile to git
2).$ git commit -m "commit name here"
make commit name meaningful

this commit name shows us what was changed, and it is easy to go back on code and find out which commit has errors, if we met errors in development.

3).$ git remote add origin <url here>
paste the url in the place where repository clone or download option

now we can push changes to remote repository.

4).$ git push origin <branch name>

by default branch name is master so, command will be like this

git push origin master

Now check GitHub repository. All changes must have been updated.

GitHub updated

That’s all, very easy ,isn’t it?😉.

Follow these steps to make your git, if you are a beginner this will help you. I will show you some other git commands in my next article.

Thank you for reading my articles. 😊

follow my YouTube channel, I have uploaded a video based on git.

follow my video on YouTube channel CODE Storm

Author:

Kavindu Gayantha

Undergraduate

BSC(Hons) in Software Engineering

University of Kelaniya.

--

--

Kavindu Gayantha

Software Engineering final year undergraduate of University of Kelaniya, Sri Lanka