Day 12 : Linux & Git-GitHub Cheat Sheet

Day 12 : Linux & Git-GitHub Cheat Sheet

Linux Basic Commands

# List all files 
ls

# Display the present working directory
pwd

# Create a directory
mkdir directory

# To go up one level of the directory tree.
cd ..

# Go to the $HOME directory
cd

# Remove (delete) file
rm file

# Remove the directory and its contents recursively
rm -r directory

# Force removal of file without prompting for confirmation
rm -f file

# Forcefully remove directory recursively
rm -rf directory

# Copy file1 to file2
cp file1 file2

# Copy source_directory recursively to destination. If destination exists, copy source_directory into destination, otherwise create destination with the contents of source_directory.
cp -r source_directory destination

# Rename or move file1 to file2. If file2 is an existing directory, move file1 into directory file2
mv file1 file2

# Create symbolic link to linkname
ln -s /filepath linkname

# Create an empty file
touch file

# View the contents of file
cat file

# Display the first 10 lines of file
head file

# Display the last 10 lines of file
tail file

# Display your currently running processes
ps

# Display all the currently running processes on the system.
ps -ef

# Display process information for processname
ps -ef | grep processname

# Display and manage the top processes
top

# Search for pattern in file
grep pattern file

# Show free and used space on mounted filesystems
df -h

Git and GitHub Basic Commands

# To check Git version
git --version

# To configure Git on your system with the username and email provided by you
git config --global user.the name "username"
git config --global user.email "email@gmail.com"

# Create and initialize a repository on the local machine 
git init [project name]

# Adding file to the staging area 
git add . or git add filename

# To record all the code changes in the repository
git commit -m " Commit Message"

# To view the changes you have made to the file
git diff <file_name>

# To display the current state of the changes in the working directory
git status

# To show the commits history made on a branch
git log

# To create a new branch
git branch <name_of_branch>

# To check the configuration of the remote server
git remote -v

# To add a remote repository to your local repository by using the command
git add remote <url_of_remote_repo>

# To change an existing remote repository URL with a new URL 
git remote set-url <remote_name> <new_url>

# To push local changes to a remote repo
git push -u <remote_name> <branch_name>

# To pull the changes from a remote repo
git pull <remote_name> <branch_name>

# To go back to the specific commit
git reset <commit_id>

# To revert and roll back a particular commit with its commit id
git revert <commit_id>

# To copy and download a project with the entire history from the remote repository
git clone <remote_repo_url>

# To switch to another branch
git checkout <branch_name>

# To display the current state of the changes in the working directory
git status

# To merge few commits into a new commit and to maintain a linear commits history
git rebase <branch_name>

# To download only the latest changes to the local repository
git fetch <branch_name>

# To switch without committing your changes to the current branch
git stash

# To reapply the previously stored changes to your working directory
git stash pop

# To select specific commits from one branch and applying them to another branch
git cherry-pick <commit-id>