# Linux & Git-GitHub Cheat Sheet

1. ## **Linux Cheat Sheet**
    

### **Basic Commands**

<table><tbody><tr><td colspan="1" rowspan="1"><p><strong>Command</strong></p></td><td colspan="1" rowspan="1"><p><strong>Description</strong></p></td></tr><tr><td colspan="1" rowspan="1"><p><code>#</code></p></td><td colspan="1" rowspan="1"><p>root user</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>$</code></p></td><td colspan="1" rowspan="1"><p>Normal user</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>/</code></p></td><td colspan="1" rowspan="1"><p>root directory</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>~</code></p></td><td colspan="1" rowspan="1"><p>home directory</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>ls</code></p></td><td colspan="1" rowspan="1"><p>Lists all files and directories in the present working directory</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>ls -al</code></p></td><td colspan="1" rowspan="1"><p>Lists files and directories with detailed information like permissions, size, owner, etc.</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>cd or cd ~</code></p></td><td colspan="1" rowspan="1"><p>Navigate to the HOME directory</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>cd ..</code></p></td><td colspan="1" rowspan="1"><p>Move one level up</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>cd</code></p></td><td colspan="1" rowspan="1"><p>To change to a particular directory</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>cd /</code></p></td><td colspan="1" rowspan="1"><p>Move to the root directory</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>cat &gt; filename</code></p></td><td colspan="1" rowspan="1"><p>Creates a new file</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>cat filename</code></p></td><td colspan="1" rowspan="1"><p>Displays the file content</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>cat file1 file2 &gt; file3</code></p></td><td colspan="1" rowspan="1"><p>Joins two files (file1, file2) and stores the output in a new file (file3)</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>mv file "new file path"</code></p></td><td colspan="1" rowspan="1"><p>Moves the files to the new location</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>mv filename new_file_name</code></p></td><td colspan="1" rowspan="1"><p>Renames the file to a new filename</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>sudo</code></p></td><td colspan="1" rowspan="1"><p>Allows regular users to run programs with the security privileges of the superuser or root</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>rm filename</code></p></td><td colspan="1" rowspan="1"><p>Deletes a file</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>man</code></p></td><td colspan="1" rowspan="1"><p>Gives help information on a command</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>history</code></p></td><td colspan="1" rowspan="1"><p>Gives a list of all past commands typed in the current terminal session</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>clear</code></p></td><td colspan="1" rowspan="1"><p>Clears the terminal</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>mkdir directory-name</code></p></td><td colspan="1" rowspan="1"><p>Creates a new directory in the present working directory or at the specified path</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>rmdir</code></p></td><td colspan="1" rowspan="1"><p>Deletes a directory</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>mv</code></p></td><td colspan="1" rowspan="1"><p>Renames a directory</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>pr -x</code></p></td><td colspan="1" rowspan="1"><p>Divides the file into x columns</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>pr -h</code></p></td><td colspan="1" rowspan="1"><p>Assigns a header to the file</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>pr -n</code></p></td><td colspan="1" rowspan="1"><p>Denotes the file with Line Numbers</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>lp -nc, lpr c</code></p></td><td colspan="1" rowspan="1"><p>Prints “c” copies of the File</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>lp-d lp-P</code></p></td><td colspan="1" rowspan="1"><p>Specifies the name of the printer</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>apt-get</code></p></td><td colspan="1" rowspan="1"><p>The command used to install and update packages</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>mail -s 'subject' -c 'cc-address'</code></p></td><td colspan="1" rowspan="1"><p></p></td></tr><tr><td colspan="1" rowspan="1"><p><code>-b 'bcc-address' 'to-address'</code></p></td><td colspan="1" rowspan="1"><p>Command to send email</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>mail -s "Subject" to-address &lt; Filename</code></p></td><td colspan="1" rowspan="1"><p>Command to send an email with an attachment</p></td></tr></tbody></table>

### ls Options

<table><tbody><tr><td colspan="1" rowspan="1"><p><strong>Command</strong></p></td><td colspan="1" rowspan="1"><p><strong>Description</strong></p></td></tr><tr><td colspan="1" rowspan="1"><p><code>-r</code></p></td><td colspan="1" rowspan="1"><p>Reverse order</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>-R</code></p></td><td colspan="1" rowspan="1"><p>Recursive list</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>-a</code></p></td><td colspan="1" rowspan="1"><p>Show all (including hidden)</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>-t</code></p></td><td colspan="1" rowspan="1"><p>Sort by last modified</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>-S</code></p></td><td colspan="1" rowspan="1"><p>Sort by file size</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>-l</code></p></td><td colspan="1" rowspan="1"><p>Long listing format</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>-1</code></p></td><td colspan="1" rowspan="1"><p>One file per line</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>-m</code></p></td><td colspan="1" rowspan="1"><p>Comma-­sep­arated output</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>-Q</code></p></td><td colspan="1" rowspan="1"><p>Quoted output</p></td></tr></tbody></table>

### **System Information Commands**

<table><tbody><tr><td colspan="1" rowspan="1"><p><strong>Command</strong></p></td><td colspan="1" rowspan="1"><p><strong>Description</strong></p></td></tr><tr><td colspan="1" rowspan="1"><p><code>hostname</code></p></td><td colspan="1" rowspan="1"><p>Shows the name of the system host.</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>hostid</code></p></td><td colspan="1" rowspan="1"><p>Displays the id of the host of the system.</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>apt-get</code></p></td><td colspan="1" rowspan="1"><p>This command is used to install and add new packages.</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>date</code></p></td><td colspan="1" rowspan="1"><p>This command is used to show the current date and time.</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>cal</code></p></td><td colspan="1" rowspan="1"><p>Shows the calendar of the current month.</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>whoami</code></p></td><td colspan="1" rowspan="1"><p>This command displays the name with which you are logged in.</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>whereis [options] fileName</code></p></td><td colspan="1" rowspan="1"><p>This command is used to find the location of the source/binary file of a command and manuals sections for a specified file in Linux System. This command is similar to the find command but this command is faster as it produces more accurate results by taking less time compared to the find command. There are again a number of options available.</p></td></tr></tbody></table>

### **File Permission Commands**

<table><tbody><tr><td colspan="1" rowspan="1"><p><strong>Command</strong></p></td><td colspan="1" rowspan="1"><p><strong>Description</strong></p></td></tr><tr><td colspan="1" rowspan="1"><p><code>r</code></p></td><td colspan="1" rowspan="1"><p>read permission</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>w</code></p></td><td colspan="1" rowspan="1"><p>write permission</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>x</code></p></td><td colspan="1" rowspan="1"><p>execute permission</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>-=</code></p></td><td colspan="1" rowspan="1"><p>no permission</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>chmod 777 filename</code></p></td><td colspan="1" rowspan="1"><p>Assign full(read, write, and execute) permission to everyone</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>chmod -R 777 dirname</code></p></td><td colspan="1" rowspan="1"><p>Assign full permission to the directory and all sub-directories</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>chmod 766 filename</code></p></td><td colspan="1" rowspan="1"><p>Assign full permission to the owner, and read and write permission to the group and others</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>chmod -x filename</code></p></td><td colspan="1" rowspan="1"><p>Remove the execution permission of any file</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>chown username filename</code></p></td><td colspan="1" rowspan="1"><p>Change the ownership of a file</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>chown user:group filename</code></p></td><td colspan="1" rowspan="1"><p>Change the owner and group ownership of a file</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>chown -R user:group dirname</code></p></td><td colspan="1" rowspan="1"><p>Change the owner and group ownership of the directory and all sub-directories</p></td></tr></tbody></table>

### **Disk Management Commands**

<table><tbody><tr><td colspan="1" rowspan="1"><p><strong>Command</strong></p></td><td colspan="1" rowspan="1"><p><strong>Description</strong></p></td></tr><tr><td colspan="1" rowspan="1"><p></p></td><td colspan="1" rowspan="1"><p></p></td></tr><tr><td colspan="1" rowspan="1"><p><code>fdisk -l</code></p></td><td colspan="1" rowspan="1"><p>List all disk partitions</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>fdisk /dev/sda</code></p></td><td colspan="1" rowspan="1"><p>Create a new partition on /dev/sda device</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>mkfs.ext4 /dev/sda1</code></p></td><td colspan="1" rowspan="1"><p>Format the partition named /dev/sda1</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>fsck.ext4 /dev/sda1</code></p></td><td colspan="1" rowspan="1"><p>Check and repair a filesystem for any error</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>mount /dev/sda1 /mnt</code></p></td><td colspan="1" rowspan="1"><p>Mount any partition to any directory</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>df -h</code></p></td><td colspan="1" rowspan="1"><p>Display free space of mounted file system</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>df -i</code></p></td><td colspan="1" rowspan="1"><p>Display free inodes on the filesystem</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>du -hs</code></p></td><td colspan="1" rowspan="1"><p>Display the size of your current directory</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>lsblk</code></p></td><td colspan="1" rowspan="1"><p>Display information about block devices</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>lsusb -tv</code></p></td><td colspan="1" rowspan="1"><p>Display all USB devices</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>hdparm -tT /dev/sda</code></p></td><td colspan="1" rowspan="1"><p>Perform a read speed test on disk /dev/sda</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>badblocks -s /dev/sda</code></p></td><td colspan="1" rowspan="1"><p>Test for unreadable blocks on disk /dev/sda</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>top</code></p></td><td colspan="1" rowspan="1"><p>Display and manage the top processes</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>htop</code></p></td><td colspan="1" rowspan="1"><p>Interactive process viewer (top alternative)</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>mpstat 1</code></p></td><td colspan="1" rowspan="1"><p>Display processor-related statistics</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>vmstat 1</code></p></td><td colspan="1" rowspan="1"><p>Display virtual memory statistics</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>iostat 1</code></p></td><td colspan="1" rowspan="1"><p>Display I/O statistics</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>tail -100 /var/log/messages</code></p></td><td colspan="1" rowspan="1"><p>Display the last 100 Syslog messages (Use /var/log/syslog for Debian-based systems.)</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>tcpdump -i eth0</code></p></td><td colspan="1" rowspan="1"><p>Capture and display all packets on interface eth0</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>tcpdump -i eth0 'port 80'</code></p></td><td colspan="1" rowspan="1"><p>Monitor all traffic on port 80 ( HTTP )</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>lsof</code></p></td><td colspan="1" rowspan="1"><p>List all open files on the system</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>lsof -u user</code></p></td><td colspan="1" rowspan="1"><p>List files opened by the user</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>free -h</code></p></td><td colspan="1" rowspan="1"><p>Display free and used memory ( -h for human readable, -m for MB, -g for GB.)</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>watch df -h</code></p></td><td colspan="1" rowspan="1"><p>Execute "df -h", showing periodic updates</p></td></tr></tbody></table>

### **User Management Commands**

<table><tbody><tr><td colspan="1" rowspan="1"><p><strong>Command</strong></p></td><td colspan="1" rowspan="1"><p><strong>Description</strong></p></td></tr><tr><td colspan="1" rowspan="1"><p><code>sudo adduser username</code></p></td><td colspan="1" rowspan="1"><p>To add a new user</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>sudo passwd -l 'username'</code></p></td><td colspan="1" rowspan="1"><p>To change the password of a user</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>sudo userdel -r 'username'</code></p></td><td colspan="1" rowspan="1"><p>To remove a newly created user</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>sudo usermod -a -G GROUPNAME USERNAME</code></p></td><td colspan="1" rowspan="1"><p>To add a user to a group</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>sudo deluser USER GROUPNAME</code></p></td><td colspan="1" rowspan="1"><p>To remove a user from a group</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>finger</code></p></td><td colspan="1" rowspan="1"><p>Shows information of all the users logged in</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>finger username</code></p></td><td colspan="1" rowspan="1"><p>Gives information about a particular user</p></td></tr></tbody></table>

### **File and Directory Compression Commands**

<table><tbody><tr><td colspan="1" rowspan="1"><p><strong>Command</strong></p></td><td colspan="1" rowspan="1"><p><strong>Description</strong></p></td></tr><tr><td colspan="1" rowspan="1"><p><code>gzip fileName</code></p></td><td colspan="1" rowspan="1"><p>This command is used to compress a file with gzip compression.</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>gunzip fileName.gz</code></p></td><td colspan="1" rowspan="1"><p>This command is used to unzip a file that has gzip compression.</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>tar cf myDir.tar myDir</code></p></td><td colspan="1" rowspan="1"><p>This command is used to create an uncompressed tar archive.</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>tar cfz myDir.tar myDir</code></p></td><td colspan="1" rowspan="1"><p>This command is used to create a tar archive with gzip compression.</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>tar xf file</code></p></td><td colspan="1" rowspan="1"><p>This command is used to extract the contents of any type of tar archive.</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>tar -cvf filename.tar filename</code></p></td><td colspan="1" rowspan="1"><p>Compress a file in the Tar archive</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>tar -xvf filename.tar</code></p></td><td colspan="1" rowspan="1"><p>Uncompress a Tar file</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>tar -tvf filename.tar</code></p></td><td colspan="1" rowspan="1"><p>List the content of the Tar file</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>tar -xvf filename.tar file1.txt</code></p></td><td colspan="1" rowspan="1"><p>Untar a single file from Tar file</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>tar -rvf filename.tar file2.txt</code></p></td><td colspan="1" rowspan="1"><p>Add a file to the Tar file</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>zip </code><a target="_blank" rel="noopener noreferrer nofollow" href="http://filename.zip" style="pointer-events: none"><code>filename.zip</code></a><code> filename</code></p></td><td colspan="1" rowspan="1"><p>Compress a single file to a zip</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>zip </code><a target="_blank" rel="noopener noreferrer nofollow" href="http://filename.zip" style="pointer-events: none"><code>filename.zip</code></a><code> file1.txt file2.txt file3.txt</code></p></td><td colspan="1" rowspan="1"><p>Compress multiple files to a zip</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>zip -u </code><a target="_blank" rel="noopener noreferrer nofollow" href="http://filename.zip" style="pointer-events: none"><code>filename.zip</code></a><code> file4.txt</code></p></td><td colspan="1" rowspan="1"><p>Add a file to a zip file</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>zip -d </code><a target="_blank" rel="noopener noreferrer nofollow" href="http://filename.zip" style="pointer-events: none"><code>filename.zip</code></a><code> file4.txt</code></p></td><td colspan="1" rowspan="1"><p>Delete a file from a zip file</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>unzip -l </code><a target="_blank" rel="noopener noreferrer nofollow" href="http://filename.zip" style="pointer-events: none"><code>filename.zip</code></a></p></td><td colspan="1" rowspan="1"><p>Display the content of the zip archive file</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>unzip </code><a target="_blank" rel="noopener noreferrer nofollow" href="http://filename.zip" style="pointer-events: none"><code>filename.zip</code></a></p></td><td colspan="1" rowspan="1"><p>Unzip a file</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>unzip </code><a target="_blank" rel="noopener noreferrer nofollow" href="http://filename.zip" style="pointer-events: none"><code>filename.zip</code></a><code> -d /dirname</code></p></td><td colspan="1" rowspan="1"><p>Unzip a file to a specific directory</p></td></tr></tbody></table>

### Networking command

<table><tbody><tr><td colspan="1" rowspan="1"><p><strong>Command</strong></p></td><td colspan="1" rowspan="1"><p><strong>Description</strong></p></td></tr><tr><td colspan="1" rowspan="1"><p><code>SSH username@ip-address or hostname</code></p></td><td colspan="1" rowspan="1"><p>login into a remote Linux machine using SSH</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>Ping hostname="" or =""</code></p></td><td colspan="1" rowspan="1"><p>To ping and Analyze network and host connections</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>dir</code></p></td><td colspan="1" rowspan="1"><p>Display files in the current directory of a remote computer</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>cd "dirname"</code></p></td><td colspan="1" rowspan="1"><p>change the directory to “dirname” on a remote computer</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>put file</code></p></td><td colspan="1" rowspan="1"><p>upload ‘file’ from a local to a remote computer</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>get file</code></p></td><td colspan="1" rowspan="1"><p>Download the ‘file’ from the remote to the local computer</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>quit</code></p></td><td colspan="1" rowspan="1"><p>Logout</p></td></tr></tbody></table>

### Process command

<table><tbody><tr><td colspan="1" rowspan="1"><p><strong>Command</strong></p></td><td colspan="1" rowspan="1"><p><strong>Description</strong></p></td></tr><tr><td colspan="1" rowspan="1"><p><code>bg</code></p></td><td colspan="1" rowspan="1"><p>To send a process to the background</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>fg</code></p></td><td colspan="1" rowspan="1"><p>To run a stopped process in the foreground</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>top</code></p></td><td colspan="1" rowspan="1"><p>Details on all Active Processes</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>ps</code></p></td><td colspan="1" rowspan="1"><p>Give the status of processes running for a user</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>ps PID</code></p></td><td colspan="1" rowspan="1"><p>Gives the status of a particular process</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>pidof</code></p></td><td colspan="1" rowspan="1"><p>Gives the Process ID (PID) of a process</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>kill PID</code></p></td><td colspan="1" rowspan="1"><p>Kills a process</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>nice</code></p></td><td colspan="1" rowspan="1"><p>Starts a process with a given priority</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>renice</code></p></td><td colspan="1" rowspan="1"><p>Changes the priority of an already running process</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>df</code></p></td><td colspan="1" rowspan="1"><p>Gives free hard disk space on your system</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>free</code></p></td><td colspan="1" rowspan="1"><p>Gives free RAM on your system</p></td></tr></tbody></table>

1. # Git & Github Cheat Sheet
    

### **Git configuration**

* **Git config**  
    Get and set configuration variables that control all facets of how Git looks and operates.  
    **Set the name:**  
    `git config --global user.name "UserName"`  
    **Set the email:**  
    `git config --global user.email "yourEmail@gmail.com"`  
    **Set the default editor:**  
    `git config --global core.editor Vim`  
    **Check the setting:**  
    `git config -list`
    
* **Git alias**  
    **Set up an alias** for each command:
    
* `git config --global alias.co checkout`
    
* `git config --global alias.br branch`
    
* `git config --global alias.ci commit`
    
* `git config --global alias.st status`
    

### Starting a project

* **Git init**  
    **Create a local repository:**  
    `git init`
    
* **Git clone**  
    **Make a local copy** of the server repository.  
    `git clone`
    

### Local changes

* **Git add**  
    **Add a file** to the staging (Index) area:  
    `git add Filename`  
    **Add all files** of a repo to the staging (Index) area:  
    `git add .`
    
* **Git commit**  
    **Record** or snapshot the file permanently in the version history **with a message**.  
    `git commit -m " Commit Message"`
    

### Track changes

* **Git diff**  
    Track the changes that have not been staged:
    
    `git diff`  
    Track the changes that have been staged but not committed:  
    `git diff --staged`  
    Track the changes after committing a file:  
    `git diff HEAD`  
    Track the changes between two commits:  
    `git diff <commit hash 1> <commit hash 2>`
    
* **Git status**  
    Display the state of the working directory and the staging area.  
    `git status`
    
* **Git show Shows objects:**  
    `git show`
    

### Commit History

* **Git log**  
    Display the most recent commits and the status of the head:  
    `git log`  
    Display the output as one commit per line:  
    `git log -oneline`  
    Displays the files that have been modified:  
    `git log -stat`  
    Display the modified files with the location:  
    `git log -p`
    
* **Git blame**  
    Display the modification on each line of a file:  
    `git blame <file name>`
    

### Ignoring files

* **.gitignore**  
    Specify intentionally untracked files that Git should ignore.
    
    Create .gitignore:  
    `touch .gitignore`
    
    List the ignored files:  
    `git ls-files -i --exclude-standard`
    

### Branching

**Git branch**

* **Create branch:**  
    `git branch`
    
* **List Branch:**
    
    `git branch --list`
    
* **Delete a Branch:**
    
    `git branch -d`
    
* **Delete a remote Branch:**
    
    `git push origin -delete`
    
* **Rename Branch:**
    
    `git branch -m`
    
* **Git checkout**  
    Switch between branches in a repository.  
    Switch to a particular branch:  
    `git checkout branch_name`  
    Create a new branch and switch to it:  
    `git checkout -b branch_name`
    
* **Git stash**  
    Switch branches without committing to the current branch. Stash current work:  
    `git stash`  
    Saving stashes with a message:  
    `git stash save ""`  
    Check the stored stashes:  
    `git stash list`  
    Re-apply the changes that you just stashed:  
    `git stash apply`  
    Track the stashes and their changes:  
    `git stash show`  
    Re-apply the previous commits:  
    `git stash pop`  
    Delete a most recent stash from the queue:  
    `git stash drop`  
    Delete all the available stashes at once:  
    `git stash clear`  
    Stash work on a separate branch:  
    `git stash branch`
    
* **Git cherry pic**  
    Apply the changes introduced by some existing commits:  
    `git cherry-pick commit_id`
    

### Merging

* **Git merge**  
    Merge the branches:  
    `git merge`  
    Merge the specified commit to the currently active branch:  
    `git merge`
    
* **Git rebase**  
    Apply a sequence of commits from distinct branches into a final commit.  
    `git rebase`  
    Continue the rebasing process:  
    `git rebase -continue`
    
    Abort the rebasing process:  
    `git rebase --skip`
    
* **Git interactive rebase**  
    Allow various operations like edit, rewrite, reorder, and more on existing commits.  
    `git rebase -i`
    

### Remote

* **Git remote**  
    Check the configuration of the remote server:  
    `git remote -v`  
    Add a remote for the repository:  
    `git remote add`
    
    Fetch the data from the remote server:  
    `git fetch`  
    Remove a remote connection from the repository:  
    `git remote rm`  
    Rename remote server:  
    `git remote rename`  
    Show additional information about a particular remote:  
    `git remote show`  
    Change remote:  
    `git remote set-url`
    
* **Git origin master**  
    Push data to the remote server:  
    `git push origin master`
    
    Pull data from the remote server:  
    `git pull origin master`
    

### Push

* **Git push**  
    Transfer the commits from your local repository to a remote server.
    
    Push data to the remote server:  
    `git push origin master`
    
    Force push data:  
    `git push -f`  
    Delete a remote branch by push command:  
    `git push origin --delete branch_name`
    

### Pull

* **Git pull**  
    Pull the data from the server:  
    `git pull origin master`  
    Pull a remote branch:  
    `git pull`
    
* **Git fetch**  
    Download branches and tags from one or more repositories.
    
    Fetch the remote repository:  
    `git fetch <repository Url>`
    
    Fetch a specific branch:  
    `git fetch`  
    Fetch all the branches simultaneously:  
    `git fetch -all`  
    Synchronize the local repository:  
    `git fetch origin`
    

### Undo changes

* **Git revert**  
    Undo the changes:  
    `git revert`  
    Revert a particular commit:  
    `git revert <commit hash>`
    
* **Git reset**  
    Reset the changes:
    
    `git reset -hard`
    
    `git reset -soft`
    
    `git reset --mixed`
    

### Removing files

* **Git rm**  
    Remove the files from the working tree and from the index:  
    `git rm <file Name>`  
    Remove files from Git But keep the files in your local repository:  
    `git rm --cached`
    

***Thank you for reading!!!***  
**~Bhaarat**
