Skip to content

Instantly share code, notes, and snippets.

View KenanBek's full-sized avatar
🐎

Kanan Rahimov KenanBek

🐎
View GitHub Profile
@KenanBek
KenanBek / git-ignore-and-pull.sh
Created February 12, 2024 19:08
Git: ignore local changes and pull from remote
git fetch --all
git reset --hard origin/master
git pull
@KenanBek
KenanBek / git-archive.sh
Created December 26, 2022 01:01
Shell script to clone repositories at a specific branch, remove the `.git` folder, and have a clean, archived copy of the repository. Read more: https://kenanbek.medium.com/archive-git-repositories-with-shell-script-987d944af769
# parse the command-line arguments
while getopts ":nh" opt; do
case ${opt} in
h)
echo "Usage:"
echo " git-clone.sh [-n]"
echo ""
echo "Options:"
echo " -n Skip commit and push"
exit 0

Useful commands to amend author and committer information.

First, basics. Setting user name and email:

# local, for project level
git config user.name "Kanan Rahimov"
git config user.email mail@kenanbek.me

# global
# This .gitignore file should be placed at the root of your git repository directory
#
# You might have as many sub-projects as you want and this configuration will ignore project specific unnecessary files
#
[Ll]ibrary/
[Tt]emp/
[Oo]bj/
[Bb]uild/
[Bb]uilds/
[Ll]ogs/
##
# Sync with upstream
###
# add upstream
git remote add upstream <git_remote_url>
# fetch changes
git fetch upstream
@KenanBek
KenanBek / git-branch-rename.sh
Last active January 3, 2022 14:27
Rename local and remote Git branch names
# rename
git branch -m new-name # option 1: when renaming the current branch
git branch -m <current_branch_name> <new_branch_name> # option 2: when renaming another branch
# delete old branch
git push origin -d <old_branch_name> # option 1
git push origin :<old_branch_name> # option 2 (shorter)
# unset upstream
git branch --unset-upstream <new_branch_name>
@KenanBek
KenanBek / nextjs_step1_package.json
Created November 12, 2020 10:31
package.json to start a Next.js app.
{
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start"
},
"dependencies": {
"next": "^10.0.1",
"react": "^17.0.1",
"react-dom": "^17.0.1"
@KenanBek
KenanBek / nextjs_index.js
Created November 12, 2020 10:21
Next.js tutorial step 1. Manual setup.
function HomePage() {
return (
<div>
<h1>Hello, Next.js!</h1>
<p>Next.js quick start tutorial with manual setup.</p>
<img src="/image1.png" />
</div>
);
}
@KenanBek
KenanBek / server.js
Created November 8, 2020 18:16
Use res.json() and accept URL parameters by using req.params object. More: https://kananrahimov.com/post/example-backend-api-in-node-js-video-tutorial/
const express = require('express');
const app = express();
//const hostname = '127.0.0.1';
const port = 3000;
app.get('/', (req, res) => {
let body = {
"message": "Hello, world!",
@KenanBek
KenanBek / server.js
Last active November 4, 2020 22:23
Simple JSON API using Node.js and Express.js. More: https://kananrahimov.com/post/example-backend-api-in-node-js-video-tutorial/
const express = require('express');
const app = express();
const hostname = '127.0.0.1';
const port = 3000;
app.get('/', (req, res) => {
res.setHeader('Content-Type', 'application/json');