Most Useful Git commands for Terminal use

Git

Downloads an Existing Git repository to your local computer.

Git
git clone

// Example: git clone https://github.com/user/git-url.git

The “clone” command downloads an existing Git repository to your local computer. You will then have a full-blown, local version of that Git repo and can start working on the project.

Typically, the “original” repository is located on a remote server, often from a service like GitHub, Bitbucket, or GitLab). That remote repository’s URL is then later referred to as the “origin”.

** Example::
In its simplest (and most common) form, only the repository URL is specified:

cd folder/to/clone-into/

This will download the project to a folder named after the Git repository (“git-crash-course” in this case). If you want a different folder name, simply specify it as the last parameter:

git clone https://github.com/user/git-url.git

This will download the project to a folder named after the Git repository (“git-crash-course” in this case). If you want a different folder name, simply specify it as the last parameter:

git clone https://github.com/user/git-url.git other-name

# Update <MyBranch> with Local


Update with Local Branch

Check current Branch:

git branch

Checkout the <MyBranch>

git checkout MyBranch

Check Status of Files:

git status

Add changes files

git add .

Commit Changes Files:

git commit -m "Any Message againt update"

Update Git repository:

git push

# Update Master with <MyBranch>

Update Master with

merge master branch with current branch:
(Currently on branch development)

$ git merge master

** here, After merge master if any merge conflicts found, resolve conflicts here & run check if it is ok.

Checkout Master:

git checkout master

Merge into Development branch:

(now, there won’t be any conflicts in Master as solved in development branch)

git merge development

git merge development 

or, Merge Branch Development with master Branch with a Commit Message

git merge <development> --commit -m "merge branch development to master"

Django- Set created & updated date/time in your models

In Django, many of us have question how to create date time in database automatically, When a new data is inserted or Existing Data is Updated.

So, Now we can use to have the date a record was added, or most recently updated. Django makes this really easy.

class Blogs(models.Model):
    title = models.CharField(max_length=100)
    added = models.DateTimeField(auto_now_add=True)
    updated = models.DateTimeField(auto_now=True)

How to hide the div one by one using jquery?

<!DOCTYPE html>
<html>
<head>
<title>Demo - Devchandan</title>
<meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"></script>
</head>
<body>

<div class="container">
	<div class="row main_block">
		<div class="col-sm-4 sub_block sub_block_1">
			<h3>Column 1</h3>
			<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit...</p>
			<p>Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris...</p>
		</div>
		<div class="col-sm-4 sub_block sub_block_2">
			<h3>Column 2</h3>
			<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit...</p>
			<p>Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris...</p>
		</div>
		<div class="col-sm-4 sub_block sub_block_3">
			<h3>Column 3</h3>        
			<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit...</p>
			<p>Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris...</p>
		</div>
	</div>
	<div class="row">
		<div class="col-sm-12">
			<button class="btn btn-primary clickme">Click Me!</button>
		</div>
	</div>
</div>

<script type="text/javascript">
	$(function(){
		var sub_blocks = [];
		$("div.main_block").find('div.sub_block').each(function(key,val){
			let subdiv_cls = 'sub_block_'+(key+1);
			sub_blocks.push(subdiv_cls);
		});	
		var blocks_display 	= sub_blocks;
		var blocks_hide 	= [];
		$('button.clickme').on('click', function(){
			var cls = blocks_display.shift();
			$.each(blocks_display, function(key,divclass){
				$('.'+ divclass).show();
			})
			$('.'+ cls).hide();
			blocks_display.push(cls);
		});
	});
</script>
</body>
</html>

How to show and hide div one by one using jquery?

Here, Suppose, have 3 Div, like Div-1,Div-2,Div-3. Now when I clicked the button , then Div-1 will hide. then Div-2, then Div-3. Finally All Div is hidden. Then when clicked again Div-1 will show, then Div-2 will show, Then Div-3 will show. This type it will function every time on clicking the button.

Here, Full page code is Given below,

<!DOCTYPE html>
<html>
<head>
<title>Demo - Show and Hide Div</title>
<meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"></script>
</head>
<body>

<div class="container">
	<div class="row main_block">
		<div class="col-sm-4 sub_block sub_block_1">
			<h3>Column 1</h3>
			<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit...</p>
			<p>Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris...</p>
		</div>
		<div class="col-sm-4 sub_block sub_block_2">
			<h3>Column 2</h3>
			<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit...</p>
			<p>Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris...</p>
		</div>
		<div class="col-sm-4 sub_block sub_block_3">
			<h3>Column 3</h3>        
			<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit...</p>
			<p>Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris...</p>
		</div>
	</div>
	<div class="row">
		<div class="col-sm-12">
			<button class="btn btn-primary clickme">Click Me!</button>
		</div>
	</div>
</div>

<script type="text/javascript">
	$(function(){
		var sub_blocks = [];
		$("div.main_block").find('div.sub_block').each(function(key,val){
			let subdiv_cls = 'sub_block_'+(key+1);
			sub_blocks.push(subdiv_cls);
		});	
		var blocks_display 	= sub_blocks;
		var blocks_hide 	= [];
		var pointdisplay = true; 
		$('button.clickme').on('click', function(){
			if(pointdisplay){
				var cls = blocks_display.shift();
				blocks_hide.push(cls);
				if(blocks_display.length == 0){ pointdisplay = false; }
			}else{
				var cls = blocks_hide.shift();
				blocks_display.push(cls);
				if(blocks_hide.length == 0){  pointdisplay = true; }
			}

			$('div.sub_block').show();
			$.each(blocks_hide, function(key,divclass){
				$('.'+ divclass).hide();
			})
		});
			
	});
</script>
</body>
</html>

Check Demo : https://jsfiddle.net/devchandansh/c3qu924h/

How to Increment value clicking plus minus icon in Jquery?

Html Code:

<div class="csdisplayorder" >
    <span class='csminus glyphicon glyphicon-minus'></span>
    <input class="cscurrent" type="text" disabled value="1" data-rid="1" data-pid="2">
    <span class='csplus glyphicon glyphicon-plus'></span>
</div>

Script:

<script type="text/javascript">
$(document).ready(function(){
    $('.csdisplayorder .csplus').live('click', function(){
        var dis = $(this);
        var input_obj = dis.parent().find('.cscurrent');
        var input_val = parseInt(input_obj.val());
        if(input_val == undefined){
            input_obj.val(0);
        }else{
            var new_val =  parseInt(input_val)+1;
            input_obj.val(new_val);
            $(this).fncsUpdateRoomDisplayOrder(dis, new_val);
        }
    });

    $('.csdisplayorder .csminus').live('click', function(){
        var dis = $(this);
        var input_obj = dis.parent().find('.cscurrent');
        var input_val = parseInt(input_obj.val());
        if(input_val == undefined){
            input_obj.val(0);
        }else{
            if(parseInt(input_val) >0){
                var new_val =  parseInt(input_val)-1;
                input_obj.val(new_val);

                $(this).fncsUpdateRoomDisplayOrder(dis, new_val);
            }
        }
    });

    $.fn.fncsUpdateRoomDisplayOrder = function(dis,nval) { 
        var input_obj = dis.parent().find('.cscurrent');
        var rid = input_obj.data('rid');
        var pid = input_obj.data('pid');

        var datastring = {'nval':nval,'rid':rid,'pid':pid}
        var xhrequest = false;
        xhrequest = $.ajax({
            url: base_url+'update',
            type:'post',
            dataType: 'json',
            data:datastring,
            async:false, 
            beforeSend: function (){
                if (xhrequest) {
                    xhrequest.ajaxStop();
                    console.log("xhrequest");
                }
            },
            success: function(data){
                xhrequest = false;
                console.log(data);
            }
        });
    }
});
</script>

CSS:

<style type="text/css">
.csdisplayorder{width: 62px;text-align: center;}
.csdisplayorder .cscurrent{width: 25px;float: none;background-color: white;border: none;text-align: center;}
.csdisplayorder .csplus,.csminus{padding: 3px;background-color: grey;color: white;border-radius: 10px;}
.csdisplayorder .csminus{float: left; }
.csdisplayorder .csplus{float: right;}
.csdisplayorder .cscurrent_txt{width:25px;float:none;vertical-align:-webkit-baseline-middle;vertical-align: sub;}
.csdisplayorder input[type=number].cscurrent::-webkit-inner-spin-button, 
.csdisplayorder input[type=number].cscurrent::-webkit-outer-spin-button { 
  -webkit-appearance: none; margin: 0; }
</style>