git

1. git is a vms/vcs version control system
2. git so fast, off line work
3. most necessity of git (code revision)

Keep in mind that it takes
	->commit(লোকাল এ যে কাজগুলি করেছেন সেগুলোকে রেকড করা) 
	->push 	(আপনি লোকাল এ যে কাজগুলি করেছেন সেগুলোকে সারভারে তোলা)
	->pull	(সারভারে থেকে কাজগুলি লোকাল এ নামানো)
	
git some of tools
	-> status		[check]
	-> add			[file add to git]
	-> diff			[if you want to see which line is modified]
	-> log			[if you want to see whole day work]
	-> show			[show up by individual hash id]
	-> checkout		[How was the whole project, if you want to go there]
	-> reset		
	-> reflog
	-> branch
	-> merge
	-> stash

Git bash cmd: 

Dell@Dell-PC MINGW64 /e/xampp/htdocs/nedstark
$ ls							[just check, is there have any file?]


$ git init						[git initialized]
Initialized empty Git repository in E:/xampp/htdocs/nedstark/.git/


$ ls -al						[list of all file]


$ echo "" > new.txt			   [new file include in git]


$ git status
Untracked files:
nothing added to commit but untracked files present (use "git add" to track)


Dell@Dell-PC MINGW64 /e/xampp/htdocs/nedstark (master)
$ git add new.txt				[file add to git]


Dell@Dell-PC MINGW64 /e/xampp/htdocs/nedstark (master)
$ git status
        new file:   new.txt

		
Dell@Dell-PC MINGW64 /e/xampp/htdocs/nedstark (master)
$ git commit -m "added some text"		[changed file to be record]
 
 
Dell@Dell-PC MINGW64 /e/xampp/htdocs/nedstark (master)
$ git status
On branch master
nothing to commit, working directory clean


Dell@Dell-PC MINGW64 /e/xampp/htdocs/nedstark (master)
$ git status
        modified:   new.txt

		
$ git diff							[if you want to see which line is modified]
diff --git a/new.txt b/new.txt
 Hello world
+
+
+Hello jupiter


Dell@Dell-PC MINGW64 /e/xampp/htdocs/nedstark (master)
$ git commit -m "added some more text" new.txt


Dell@Dell-PC MINGW64 /e/xampp/htdocs/nedstark (master)
$ git status
On branch master
nothing to commit, working directory clean


Dell@Dell-PC MINGW64 /e/xampp/htdocs/nedstark (master)
$ git log						[if you want to see whole day work]


Dell@Dell-PC MINGW64 /e/xampp/htdocs/nedstark (master)
$ git show 95fdea				[individual hash id]


Dell@Dell-PC MINGW64 /e/xampp/htdocs/nedstark (master)
$ git checkout 95fdea			[How was the whole project, if you want to go there]
Note: checking out '95fdea'.


Dell@Dell-PC MINGW64 /e/xampp/htdocs/nedstark ((7588b3e...))
$ cat new.txt					[if you want to see file content]


Dell@Dell-PC MINGW64 /e/xampp/htdocs/nedstark ((7588b3e...))
$ git checkout master			[if you want to back last commit]
Switched to branch 'master'


Dell@Dell-PC MINGW64 /e/xampp/htdocs/nedstark (master)
$ git log


Dell@Dell-PC MINGW64 /e/xampp/htdocs/nedstark (master)
$ git reset --soft 95fdea		[soft reset]


Dell@Dell-PC MINGW64 /e/xampp/htdocs/nedstark (master)
$ git diff HEAD					[if you want to see changed line]


Dell@Dell-PC MINGW64 /e/xampp/htdocs/nedstark (master)
$ git reset --hard 95fde		[Hard reset]


Dell@Dell-PC MINGW64 /e/xampp/htdocs/nedstark (master)
$ git reflog					[if you want to back reset file]


Dell@Dell-PC MINGW64 /e/xampp/htdocs/nedstark (master)
$ git reset HEAD@{1}
Unstaged changes after reset:
M       ami.txt


Dell@Dell-PC MINGW64 /e/xampp/htdocs/nedstark (master)
$ git reset --hard
HEAD is now at 9999cf3 Three


Dell@Dell-PC MINGW64 /e/xampp/htdocs/nedstark (master)
$ git stash						[Temporary save]


Dell@Dell-PC MINGW64 /e/xampp/htdocs/nedstark (master)
$ git stash pop					[return code from stash]


Dell@Dell-PC MINGW64 /e/xampp/htdocs/nedstark (master)
$ git stash list				[list of stash]


Dell@Dell-PC MINGW64 /e/xampp/htdocs/nedstark (master)
$ git stash clear				[if you want to clear stash list]


Dell@Dell-PC MINGW64 /e/xampp/htdocs/nedstark (master)
$ git remote add origin https://github.com/md-ataur/git-test.git   

								
Dell@Dell-PC MINGW64 /e/xampp/htdocs/nedstark (master)
$ git remote show


Dell@Dell-PC MINGW64 /e/xampp/htdocs/nedstark (master)
$ git remote show origin


Dell@Dell-PC MINGW64 /e/xampp/htdocs/nedstark (master)
$ git push origin master
Username for 'https://github.com': md-ataur


Dell@Dell-PC MINGW64 /e/xampp/htdocs/nedstark (master)
$ git pull origin master


Dell@Dell-PC MINGW64 /e/xampp/htdocs/nedstark (master)
$ echo "" > .gitignore


Dell@Dell-PC MINGW64 /e/xampp/htdocs/nedstark (master)
$ git status
On branch master
Untracked files:
     .gitignore				[edit page and put this *.zip]



Dell@Dell-PC MINGW64 /e/xampp/htdocs/nedstark (master)
$ git add new.zip
The following paths are ignored by one of your .gitignore files:
new.zip
Use -f if you really want to add them.

Dell@Dell-PC MINGW64 /e/xampp/htdocs/nedstark (master)
$ git add .gitignore

Dell@Dell-PC MINGW64 /e/xampp/htdocs/nedstark (master)
$ git commit -am "gitignore"




File Download

/* download.php */

<?php

if (isset($_GET['file_name'])) {
    $filename = $_GET['file_name'];
} else {
    $filename = NULL;
}

$err = "Sorry, the file you are requesting is unavailable";

if (!$filename) {
    echo $err;
} else {
    $path = 'uploads/' . $filename;
    if (file_exists($path) && is_readable($path)) {
        $size = filesize($path);
        header('Content-Type: application/octet-stream');
        header('Content-Length: ' . $size);
        header('Content-Disposition: attachment; filename=' . $filename);
        header('Content-Transfer-Encoding: binary');

        $file = @fopen($path, 'rb');
        if ($file) {
            fpassthru($file);
            exit;
        } else {
            echo $err;
        }
    }
}
?>

File upload & Delete

<?php
$conn = mysqli_connect("localhost", "root", "", "fresh");

/* This is for delete file */
/*
if (isset($_REQUEST['file_name'])) {
    $filename = $_REQUEST['file_name'];
    $query = mysqli_query($conn, "DELETE FROM user WHERE profile_image='$filename'");
    if (mysqli_affected_rows($conn) > 0) {
        @ unlink("uploads/$filename");
        echo "Your file succefully delete";
    } else {
        echo "Your file not delete";
    }
}
 * */



/* file upload from this here */
if (isset($_FILES['filefield'])) {

    $name = $_REQUEST['name'];
    $file = $_FILES['filefield'];
    //echo "<pre>";
    //print_r($file);

    $upload_directory = "uploads/";

    $allowed_extensions = array("gif", "jpg", "jpeg", "mp3", "mp4", "tiff", "bmp", "doc", "docx", "ppt", "pptx", "txt", "pdf");
    $ext = substr($file['name'], strrpos($file['name'], '.') + 1);
    if (!in_array($ext, $allowed_extensions)) {
        die('only "gif", "jpg", "jpeg", "mp3", "tiff", "bmp", "doc", "docx", "ppt", "pptx", "txt", "pdf" files allowed to upload');
    }

    $max_file_size = 10485760;
    if ($file['size'] >= $max_file_size) {
        echo "Only the file size less than $max_file_size mb allowed";
    }

    $path = md5(microtime()) . '.' . $ext;

    if (move_uploaded_file($file['tmp_name'], $upload_directory . $path)) {

        // This query file name insert in to the database
        $query = mysqli_query($conn, "INSERT INTO user SET name='$name', profile_image='$path' ");

        //if (move_uploaded_file($file['tmp_name'], $upload_directory . $file['name'])) {
        echo "Your file successfully uploaded";
    } else {
        echo "The file can't moved";
    }
}
?>
/* file upload finished */

<form action="" method="post" enctype="multipart/form-data">
    <label>Name
        <input id="name" type="input" name="name" />
    </label>

    <label>Upload File
        <input id="filefield" type="file" name="filefield" />
    </label>

    <label>
        <input id="Upload" type="submit" name="Upload" value="Submit" />
    </label>



    <!-- This part is file name fetch from database and show up table -->

    <table width="700" border="1">
        <tr>
            <td>Name</td>
            <td>File Name</td>
            <td>Image</td>
        </tr>

        <?php
        /*
        $query = mysqli_query($conn, "SELECT name, profile_image FROM user");
        $hold = mysqli_fetch_all($query, MYSQLI_ASSOC);
        //echo "<pre>";
        //print_r($show);
        foreach ($hold as $data) {
            extract($data);
            ?>     
            <tr>
                <td><?php echo $name; ?></td>
                <td><?php echo $profile_image; ?></td>
                <!--<td><img src="uploads/<?php //echo $profile_image;?> "/></td>-->
                <td>
                    <?php
                    $file_ext = substr($profile_image, strrpos($profile_image, '.') + 1);
                    if ($file_ext == 'jpg') {
                        ?>
                        <img src = "uploads/<?php echo $profile_image; ?>" width = "100" />
                        <?php
                    }

                    if ($file_ext == 'pdf') {
                        ?>
                        <a href="uploads/<?php echo $profile_image; ?>"><img src = "uploads/pdf.jpg" width = "100" /></a>
                        <?php
                    }
                    if ($file_ext == 'docx') {
                        ?>
                        <a href="uploads/<?php echo $profile_image; ?>"><img src = "uploads/docx.jpg" width = "100" /></a>
                        <?php
                    }
                    ?>
                    <a href="download.php?file_name=<?php echo $profile_image; ?>"><input type="button" value="Download" name="download"></a>
                    <a href="upload.php?file_name=<?php echo $profile_image; ?>"><input type="button" value="Delete" name="delete" /></a>     
                </td>

            </tr>
            <?php
        }
        
        */
        ?>
    </table>

</form>