Skip to main content

Git Cheatsheet [Commonly used commands]

In this post I have made a cheat-sheet of commonly used or most frequently used git commands .Just to make you feel about  git commands I referred this post  first rather than the post about setting git.I would be covering that in my next post.So you don't have have to worry.It will be a step by step procedure. Please feel free to comment if you have any doubt or want me to add something else.I would be happy to help you.

CHEAT-SHEET


Cloning a repository : git cone <ssh-path of the repository>

Creating a branch : git branch <branch name> // This will make a new branch that will have all contents and commits of the current branch you are in right now.


Changing branches (Moving form one branch to another): git checkout <branch name>

Deleting a branch: First checkout to some other branch using the previous command.Then
use git branch -d <branch name to be deleted>

Showing the list of files being tracked (Both staged and unstaged) : git status

Adding files to staging area or to be tracked : git add <file name>
and if you want to add all files in project to be tracked then git add . (this dot after add is required and its not a full stop )


Commiting a change : git commit -am “commit message ”

Rebase history of one branch with another : git rebase <source branch> <destination branch>

N.B: Rebasing will only be successful if you dont have any merge conflicts.But if merge conflicts occur then we have to first resolve them manually then continue the rebase.


Checking the remote connections to your local repo : git remote -v

By default it would be named origin and would have the ssh link of the remote repo from where you have cloned.

Adding a remote other than origin: git remote add <name> <ssh link of the other github repo>


Show all commit log for a branch : git log

For each commit there would be its details also which consists of short commit message and ID of the commit


Picking up commit from one branch to another : git cherrypick <commit id>

Pull the lastest code to the current branch : git pull <name of the remote repo> < branch of the remote repo>

Eor ex : git pull origin master
This pulls the latest code from master branch of the repository specified in origin

Push your code to the github repo's particular branch : git push <<name of the remote repo> <branch of the remote repo> -f

N:B -f stands for forced push

Comments

Popular posts from this blog

Introduction to GIT and GITHUB

In this series I would be covering the basic operation of  GIT so that even a new comer can easily feel comfortable with the terminologies and usage of git system. The first post is just a brief introduction that will help you clarify the questions raising about this new thing. What is a Git? Git is simply a software that helps you manage your source code.That means each change that you make to a source code is recorded in its history.So it can also be called as Source Code managemnt system. To use git for a particular project all you need is to initialize the current project folder so that it will be tacked by the git system.I will show it in further documents about how to do it. Every Git working directory(or you can say your project folder) is a full-fledged repository with complete history and full version tracking capabilities, not dependent on network access or a central server. What is GitHub ? In layman terms you can think of

Difference between spin locks and semaphores--Some Notes

up vote down vote accepted Both manage a limited resource. I'll first describe difference between binary semaphore (mutex) and spin lock. Spin locks  perform a busy wait - i.e. it keeps running loop(In turn heavy CPU usage example is in Reactor usage of AsyncTaskExecutors): while (try_acquire_resource ()); ... release(); It performs very lightweight locking/unlocking but if the locking thread will be preempted by other which will try to access the same resouce the second one will simply try to acquitre resource untill it run out of it CPU quanta. On the other hand  mutex  behave more like: if (!try_lock()) { add_to_waiting_queue (); wait(); } ... process *p = get_next_process_from_waiting_queue (); p->wakeUp (); Hence if the thread will try to acquire blocked resource it will be suspended till it will be avaible for it. Locking/unlocking is much more heavy but the waiting is 'free' and 'fair'. Semaphore  is a lock that is allowed to

Write a program such that given a BST,return the size of largest subtree that lies within a given range[a,b].

Write a program such that given a BST,return the size of largest subtree that lies within a given range[a,b]. N.B: This  exact question was asked in a Google interview.  This problem when looked at first looks simple and may be for some it it but for me when it wasn't because when I started coding it I got all confused between recursions and the flow the algorithm will take.So i started simple on pen and paper tried for a couple of hours and could make it work . Point to be noted here is that the following approach here I took is not the most  efficient way but yes it does works perfectly. Steps or rather my thoughts : I had to touch each node so that I can calculate the size of the subtree in case the tree below and the node itself lied in the range.And after i calculate it I have maintained a global variable that stores the current max and when new value comes it compares it with existing one and updates it with the max value between them. To do so ,we