Thursday, September 4, 2014

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.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Istio —simple fast way to start

istio archeticture (source istio.io) I would like to share with you a sample repo to start and help you continue your jou...