Handful git commands

I’m going to list out few helpful git commands here which might be very handy specially when you’re a noob like me with a thurst to learn a lot 😛

Few golden rules while you’re working with git.

#1. Always pull from remote repository before you push your files to remote.
#2. Use git status to see status of your local repo after/before pull/push.
#3. Generally we work on development branch rather than master branch. TL/PM should merge the files from development to master branch after reviewing them.
#3. You can create a branch if you’re working on a new module from scratch.
#4. You can draft (called stash) your changes in your local repo using git stash commands if you don’t want to push the changes now.


Register your identity in your local system using:

git config --global user.name "user_name"
git config --global user.email "user_email"

Git initialization

If you have created a new directory and want to initiate git in it

cd /path/to/my/directory
git init

Git Add and commit

If you’ve modified some files in your local repo, you need to add it to git before pushing to remote repo. Add a file to git using

git add <file_name>

Add all modifiled files to git using

git add . 
git add -A

Commit files using

git commit -m “commit message”

Note: Check the status using git status.

Git pull

git pull origin <branch_name>
Ex: git pull origin development

Git push

git push origin <branch_name>
Ex: git push origin development

Fixing git conflicts:

Check logs

If you see there are pull/push/merge conflicts and want to revert back to previus commits, use command git log to see log history and get commit id from it and afterwards reset it using

git reset <commit_id> 

It will update your repo with the code to the version when commit_id was commited.


When you initiate git in new directory using git init, automatically master branch will get created.Though if you want to create new branch you can use git checkout -b to create new branch and switch to newly created branch.

Use following commands to show list of branches

git branch 
git branch -a

If there is a branch with name branch_name on remote repo but not in your local repo. Use this command to update your local repo and switch to new branch:

git fetch && checkout <branch_name>

Merging branches

git checkout <base_branch>
git merge <branch_to_merge>

Stashing/Drafting your changes

Use following command to stash/draft your changes in local repo.

git stash

Use following command if you don’t want to keep changes or delete them:

git stash drop 

If you’ve modifed any local file, then added that file to gitignore, still you’ll see that file will be present in index (git status). You can clear your screen using below command

git update-index --assume-unchanged <file_name>

I’ll keep extending this list based on your suggestions and my experiences.

Understanding GitHub

Many of the linux user programmers are always in a confusion that where  they should contribute their software development project and from where to take help on the project.I am here with a solution to that with a very famous social coding site GitHub. In starting you will be little uncomfortable to the site but when you will be familiar with this,it will be interesting.Now question arieses that what is GitHub?

GitHub is a webased hosting service for software development projects. Git is a fast, open source, distributed version control system(VCS) that is quickly replacing subversion in open sourse and corporate programmin communities. GitHub also provides the funtionality of social networking such as feeds, followers and the network graph to display how developers work on their versions of repository.

Repository?? In git everything happens inside a repository. The repository for a project contains all the files that belong to that project along with a historic record of the project’s files.Repository is simply a directory tree in your filesystem that git treats as special.

Their are many repositorys present on the host and if we want to work on someone others project then we can also do that.The “git clone” command is used to create a local copy of a remote repository. This is genrally the first git operation you will use when begining to work with an existing project.

Fork?? Forking is copying a repository from one user’s account to another. This enables you to take a project that you don’t have write access to and modify it under your own account.

Pull request?? If you have make changes in the project and if youlike tostore , you can send a notification called a pull request to the original owner. That user then can with a click of a button ,merge the changes found in your repo with the original repo. this three features- fork. pull request and merge are what makes GitHub so powerful.

I hope you have got a brief concept abot GitHub. Now you can start working with it. Soon i will be present with the secnd post on developing projects. Any suggestions are welcomed.