Skip to main content

Git & Git hub 101

step by step on using git hub for first time

create an account on GitHub.com :

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


a

b
c

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 (http://git-scm.com/downloads) 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 git@github.com:blabadi/hello-world.git ./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 :
https://help.github.com/articles/generating-ssh-keys


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 

a


b
c



d
e



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

============================================================
Note the below segment is taken from : 
https://github.com/GarageGames/Torque2D/wiki/Cloning-the-repo-and-working-with-Git

Important Git concepts:


Repository / Repo : This is the project's source code that resides on github.com'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 github.com 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 github.com 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.

Comments

Popular posts from this blog

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:

https://developer.android.com/training/material/lists-cards.html

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(R.id.mylist_empty_view);
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.

Android - Multiple themes for one application

Sometimes you want to have multiple themes for your app
one strong example is having the ability to switch between dark and light themes because during night, a white bright screen can really be annoying for users eyes

Android will do most of the work for you but it may be required to change icons between themes to fit colors
In this blog I'll show a simple app with both dark and light themes and how to change icons without having to do that from code and keep things clean and centralized.
first of all let's create our activity, it will look something like this :


In /rest/values/styles.xml, we inherit Theme.AppCompat
 <!--
        Base application theme, dependent on API level. This theme is replaced
        by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
    -->
    <style name="AppBaseTheme" parent="Theme.AppCompat">
        <!--
            Theme customizations available in newer API levels can go in
            res/values…

Creating your own OAuth2 server and clients using spring security - part 1

In this series of posts, I'll try to put together a simple working example on how to create your own OAuth2 server.

if you want to know more on OAuth2 and when to use it as authentication and authorization protocol then you can search about it on google and i'll put some URLs later.

Now I assume you are familiar with java web applications using Spring and maven.

to get started we need to create the server side with all dependencies required and i'll list them here, i'll use maven 2 to ease downloading dependencies for us.


Steps:

1- Create new maven project with arch type webapp:



2- Add the required depenedencies for spring, spring security, spring-oauth2, hibernate & other libraries (required for this tutorial only you can use other libraries if you like)

https://gist.github.com/anonymous/d33a31ddc3ba84375cf3

3- I used hibernate to automate the creation of the schema required by spring OAuth2 to manage tokens (it's required to have schema created in db if you a…