Skip to content

Instantly share code, notes, and snippets.

@NaitikShah
Last active June 24, 2020 03:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NaitikShah/8718947ff50b2a5ceb8cce7e65cbe614 to your computer and use it in GitHub Desktop.
Save NaitikShah/8718947ff50b2a5ceb8cce7e65cbe614 to your computer and use it in GitHub Desktop.
I have made this gist as I had found this commands useful in every developer days

Oh Crap! I don't know Markup !!

No worries Click-Me


Install Nginx


GIT COMMANDS

Want to create a new branch

   git checkout -b branch-name
   # when you run this command it will take checkout from branch in which you currently are.

Having merge conflicts, no worries resolve with mergetool

    git mergetool

Want to push, pull and merge the code.

    git pull origin branch-name

    git add file-name

    git commit -m "commit-message"

    git push origin branch-name

    git merge branch-name

Want to rename git local and remote branches

  1. Rename your local branch.

    If you are on the branch you want to rename:
    
    git branch -m new-name
    If you are on a different branch:
    
    git branch -m old-name new-name
    
  2. Delete the old-name remote branch and push the new-name local branch.

    git push origin :old-name new-name
  3. Reset the upstream branch for the new-name local branch.

    Switch to the branch and then:
    
    git push origin -u new-name
    
    ## Or you as a fast way to do that, you can use these 3 steps: command in your terminal
    
       git branch -m old_branch new_branch         
       # Rename branch locally    
    
       git push origin :old_branch                 
       # Delete the old branch    
    
       git push --set-upstream origin new_branch   
       # Push the new branch, set local branch to track the new remote
  4. Delete local branch and then the remote branch.

    git branch -d branch_name   
    # The -d option stands for --delete, which would delete the local branch, 
    only if you have already pushed and merged it with your remote branches.
    
    git branch -D branch_name
    # The -D option stands for --delete --force, which deletes the branch regardless 
    of its push and merge status, so be careful using this one!

AWS HELP

To see the description of AWS profile

aws ec2 describe-instances --profile profile-name
# get the profile name from ~/.aws/config

To activate AWS profile

export AWS_PROFILE=profile-name

Want to add a service to run on startup in a unix file system.

vim /etc/systemd/system/start_docker.service
sudo vim /usr/local/bin/start-docker.sh
sudo chmod 744 /usr/local/bin/start-docker.sh
sudo chmod 664 /etc/systemd/system/start_docker.service
sudo systemctl daemon-reload
sudo systemctl enable start_docker.service 

Want to drop complete public schema and create new in Postgres

DROP SCHEMA public CASCADE;
CREATE SCHEMA public;
-- If you are using PostgreSQL 9.3 or greater, you may also need to restore the default grants.

GRANT ALL ON SCHEMA public TO postgres;
GRANT ALL ON SCHEMA public TO public;

Want to backup and restore PostgreSQL data used in Docker

For Backup
	docker exec -t your-db-container pg_dumpall -c -U postgres > dump_`date +%d-%m-%Y"_"%H_%M_%S`.sql

For Restore
	cat your_dump.sql | docker exec -i your-db-container psql -U postgres
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment