Skip to content

Instantly share code, notes, and snippets.

$#, $@ & $?: Bash Built-in variables

file:test.sh
#! /bin/sh
echo '$#' $#
echo '$@' $@
echo '$?' $?

*If you run the above script as*

To do so, specify the -r (or --recursive) option:

$ cp -r ../.git .

Must know Git commands

Updated Apr 29, 2020

Show differences

If you want see the differences between local and remote files:

$ git diff master origin/master
zip -r folder1 folder1 -x exclude1 exclude2
@albertpark
albertpark / license
Last active May 11, 2020 21:06 — forked from defunkt/license
license bash script
#!/bin/sh -e
# Usage: license
# Prints an MIT license appropriate for totin' around.
#
# $ license > COPYING
#!/bin/sh
echo "Copyright (c) `date +%Y` Albert Park
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the

Using command-line Git with GitHub 2FA

Updated Apr 18, 2020

After enabling two-factor authentication on my GitHub account it seemed I became unable to push my local repositories from command-line git using the https transport.

I was simply wrong, here what I did to fix the issue.

Create a Personal Access Token

Two-factor authentication in GitHub works by replacing your GitHub password with a Personal Access Token which can be different depending on the application you want to enable.

@albertpark
albertpark / git-pushing-multiple.md
Last active May 7, 2020 20:18 — forked from rvl/git-pushing-multiple.rst
How to push to multiple git remotes at once. Useful if you keep mirrors of your repo.

Pushing to Multiple Git Repos

Updated May 7, 2020

If a project has to have multiple git repos (e.g. Bitbucket and Github) then it's better that they remain in sync.

Usually this would involve pushing each branch to each repo in turn, but actually Git allows pushing to multiple repos in one go.

Importing a Git repository using the command line

Before you start, make sure you know:

  • Your GitHub username
  • The clone URL for the external repository, such as https://external-host.com/user/repo.git or git://external-host.com/user/repo.git (perhaps with a user@ in front of the external-host.com domain name)

For purposes of demonstration, we'll use:

  • An external account named extuser
  • An external Git host named https://external-host.com

SSH Getting Started for a Repository

This guide all started because of the infamous Permission Denied (publickey) when trying to push code to my repository. Before we can start using repositories intensively there are prequisties that we must complete in order to get our work flowing.

We will be using git bash (Use the Windows search. To find it, type "git bash") or the Mac Terminal. You can also use the default Windows Command Prompt by installing git from git-scm.
Tip: You can use any *nix based command prompt

1. SSH Agent

First thing is first, we must first identify if the ssh-agent is enabled and running properly. If this is not an issue go to step 2.

Linux

Recover Deleted Files in My Local Repository using Git

You can view a list of all the deleted files using the command.

$ git ls-files --deleted

Use this this command to restore your deleted file. Replace the <deleted-file> with the deleted filename.

$ git checkout --