Skip to main content

Git & Git hub 101

step by step on using git hub for first time

create an account on :

1- create a repository

2- create a new branch on the remote repository

if you don't have a read me file, you will not see the branches so click on README



the new branch is to avoid messing the master branch (default branch) this is a good practice to create branches for every feature you work on then merge these branches to master after everything is tested on the branch itself to keep master working and clean.

3- install git bash ( on your machine and create a directory to host the remote repository locally

> mkdir newDir
> git clone repository_name /path/to/localrepo/
in my case it will be 
> git clone ./newDir

Info : to paste in git bash use ctrl + Insert

from the first try this command failed with me, because I haven't generated an SSH key
to fix that I had to verify my email address to git hub, they sent u an email with link
then follow this guide :

i'll try again now

ok done!

4- now let's check what we have in the directory

the .git file is for git not us.. the read me file is the only file we have right now.

ok let's navigate to the repo dir in git bash and see

you will see this : ' ~/blabla/newDir (master)'

this means that we are now in the repo directory and the active branch is master

5- let's switch to dev branch : 

6- now let's add a new file and modify read me file
I created a new file called simple.txt inside the repo directory, let's see how can we see that change in gitbash:

this indicates that git has detected a new file but currently it's not tracked and is not included in the commit if we commit. to add it do the following:

Now it's ready to be commited :

now our 'local' dev branch has simple.txt, but if we check online the 'remote' repo doesn't 

Git is a distributed Version control system, it has the concept of Remote and Local repositories
Remote repositories act as servers, central points, while local repositories are a clone of the remote repositories but are only used and changed on your machine.

so the work flow for a branch is as following:

create local branch -> do work locally ->commit work -> push to remote branch -> repeat

there are more steps but we will go over them later.

7- let's push our changes to the remote dev branch:

Now check Git hub :

as you can see simple.txt is now there.

try and modify read me file, it goes in the same cycle and steps.

8- let's merge now the remote dev branch with master branch
to do this we need to do a pull request 




As you can see in the last image, master now has simple.txt file.

Note the below segment is taken from :

Important Git concepts:

Repository / Repo : This is the project's source code that resides on's servers. You cannot modify the contents of this repository directly unless you were the one who created it in the first place.

Fork : Forking a project will create a copy of the original repository that you can modify as you please. Forked projects will appear in your own account.

Cloning : this will clone an online repository to your hard drive so you may begin working on your modifications. This local copy is called your local repository.

Branch : A branch is a different version of the same project.

Remote : A remote is simply an alias pointing to an online repository. It is much easier to work with such aliases than typing in the complete URL of online repositories every single time.

Staging Area : Whenever you want to update your online repository (the one appearing in your account), you first need to add your changes to your staging area. Modifying files locally will not automatically update yourstaging area's contents.

Important Git commands

Fetch : git fetch will download the current state (containing updated and newly created branches) of an online repository without modifying your local repository. It places its results in .git/FETCH_HEAD.

Merge : git merge will merge the modifications of another branch into the current working branch.

Pull : git pull is actually a combination of git fetch and git merge. It fetches the information from an online repository's branch and merges it with your local copy.

Add : Whenever you modify a file in your local repository or create a new file, that file will appear as unstaged. Calling git add allows you to specify files to be added to your staging area.

Commit : A commit records a snapshot of your staging area, making it ready to be pushed to an online repository.

Push : git push will take all of your locally committed changes and upload them to a remote repository's branch.


Popular posts from this blog

Spring 4 + Hibernate 4 / Java configuration / rest service example with gradle

In this post I'll explain the required work to create a rest API utilizing both spring and hibernate version 4, and the configuration will be using java configuration classes not XML. I'll use gradle to build and for dependency management, it's way easier than maven and keeps you focused on the application, if you are not familiar with gradle and interested in it see my previous post about it. The first part which is dependency management is covered in gradle post mentioned above. I'll skip to explain each tier of the project and its configurations: As you can see we have 4 tiers: 1) DAO tier / data tier In this tier we configure the datasource and hibernate, I used HSQL in memory db it can be easily substituted with other db engine providing the right dependencies The DaoConfig defines the data source, transaction manager, session factory and  hibernate properties The most important part is the annotations : 1)  @Configuration  : to tell spring th

Android RecyclerView - Adding Empty View

So RecyclerView was introduced to replace List view and it's optimized to reuse existing views and so it's faster and more efficient as stated in the documentation: While using it, I faced the issue of missing a useful functionality that is implemented in ListView. that feature is setting an empty view in case there was no records. In ListView it was as simple as this View emptyView = findViewById(; ListView  myList = .... myList.setEmptyView(emptyView); but this method doesn't exist for recycler view so we need a work around until android team fixes this. and here are the screen shots of both list view and recycler view fix List view : Recycler view : here is how I fixed it: here is the content of empty_view, it can be anything. Enjoy.

[PART 5] NuTracker ReactJS app - Add Login & Profile using Router

In the previous part we finished the dashboard read functionality, now we want to add the skeleton for other pages: - Login   In this page the user will be able to login to their account and the dashboard won't show unless the user is logged in. - Profile In this page the user will be able to update their daily nutrition goals that they can track in the dashboard. to be able to have multiple 'pages' in react and navigate from one to one, we need something that can switch the rendered content based on what we want, we can do that with if statements in the App components and store some location state, but why invent the wheel. React Router every major single page app web framework has the routing concept and functionality to interact with the usual browser urls and switch the content based what user should see. for example on the profile page I want the url path to be /profile, and for login to be /login and so on. in more advanced cases you want the users