Basic Git tutorial

You have created and Committed your first file to github in my first git Tutorial. If anyone can not read my first tutorial, Click here to read it.

In This tutorial, I am going to teach you some basic git commands.


Open your git shell and type git init to initialize empty git repository or Reinitialize the git repository If you configured the git repositories before.
> git init

Type git status to know which git commands should issue next. git status command says that what should you do next.
>git status

In my Example, It says there are few number of files to be added to git repository. So I have to add these files to git repository. Issue following command to add files to git repository.

To add several files to git repository, Type following command
> git add --all
or
>git add .

If you have single file to add git repository, Type following git command.
> git add filename

again type git status command. Now git says Type git commit command.
> git commit -m "Leave your commit message here"

If you want add all files in single extension. type following git command in git shell.
> git add '*.php'

Now you can add remote repository to puch your local git repository to remote git repository.
> git remote add origin https://github.com/your_repo.git

Ok. In this step you have to tell where to put your local repository. I am pushing my local repository to master branch in remote git repository.
>  git push -u origin master

If you want to get source file in master branch, Issue pull request.
> git pull origin master

If you want to create branch like production, testing, development etc... type following command to create new branch. Creating branches is more useful to manage version system. We Can prevent unwanted merging master branch source from other branch sources.

Type following command to create a Branch
> git branch development

To get source in development branch, type following command.
> git checkout development

Once you enter this command, all changes in development will downloaded to your local repository. your Current work is overwrite So save changes to git repository before checkout another branch.

Lets move to another topic. If you want to move your changes in development branch to master branch. It can easily do with git hub using git merge command. Be careful with this command because your source in master branch will overwrite with development branch source.
> git checkout development

It checkout your source in development branch. Then Type merge command.
> git merge master

It merges changes in development branch with master branch.

Have a Nice Day !


0 comments:

Post a Comment

Ask anything about this Tutorial.