Useful Links

Git Command Explorer — Find the right commands you need without digging through the web.

Prerequisites

Setup a local folder for your GIT repo
Go to github and create the repo
Once the repo is created, transfer your files into the folder and git push them

Setup using HTTPS

…or create a new repository on the command line

echo "# github-test" >> README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin https://github.com/yourname/github-test.git
git push -u origin master
git remote add origin https://github.com/yourname/github-test.git
git push -u origin master
git clone https://github.com/yourname/test-db.git
git push

Useful CLI Commands

Visual Studio Code on macOS
Visual Studio Code on Windows
Visual Studio Code on Linux

Basic GIT Commands

cd into the folder with your files

git remote add new-remote-repo https://github.com/yourname/github-test.git
git push new-remote-repo test1
git checkout master
git checkout test1
git checkout test2
git push --set-upstream origin test1
git push origin test1
git branch -d the_local_branch
git push origin --delete the_remote_branch
git clone https://github.com/yourname/github-test.git
cd github-test

Basic GIT Merge and Merge Conflict Workflow Commands

Git & GitHub Tutorial for Beginners #9 — Merging Branches (& conflicts) — YouTube

git branch example1
git checkout example1
git add .
git commit -m "Your commit message"
git checkout master
git merge example1
git push
  1. Add the files to the staging area
git add .
git commit
:wq
git log --oneline

Basic GIT Rebase Commands

Rewriting Commit Messages in Git

For rewriting previous commit messages

To redo the last commit’s message

Retrieve specific commit from a remote Git repository

git fetch — Retrieve specific commit from a remote Git repository — Stack Overflow

git init
git pull --rebase <repo> 
git pull --rebase https://github.com/yourname/test.git
git pull --rebase <repo> <branch>
git pull --rebase https://github.com/yourname/test.git tree1
git reset --hard <commit-hash>
git reset --hard 83d515fd4149dd8608f38ab02314897276c0307b

Git Stash

Git Tutorial: Using the Stash Command — YouTube

Deploying a subfolder to GitHub Pages

Sometimes you want to have a subdirectory on the master branch be the root directory of a repository’s gh-pages branch. This is useful for things like sites developed with Yeoman, or if you have a Jekyll site contained in the master branch alongside the rest of your code.

Step 1

Remove the dist directory from the project’s .gitignore file (it’s ignored by default by Yeoman).

Step 2

Make sure git knows about your subtree (the subfolder with your site).

git add dist && git commit -m "Initial dist subtree commit"

Step 3

Use subtree push to send it to the gh-pages branch on GitHub.

git subtree push --prefix dist origin gh-pages
#!/bin/sh
if [ -z "$1" ]
then
echo "Which folder do you want to deploy to GitHub Pages?"
exit 1
fi
git subtree push --prefix $1 origin gh-pages
git gh-deploy path/to/your/site

VIM Mode Commands

Basic Vim commands — For getting started (Example)

  1. Command mode (Where you give commands to the editor to get things done. Press ESC for command mode)
  • u — to undo the last the command and U to undo the whole line
  • CTRL-R to redo
  • A — to append text at the end
  • :wq — to save and exit
  • :q! — to trash all changes
  • dw — move the cursor to the beginning of the word to delete that word
  • 2w — to move the cursor two words forward.
  • 3e — to move the cursor to the end of the third word forward.
  • 0 (zero) to move to the start of the line.
  • d2w — which deletes 2 words .. number can be changed for deleting the number of consecutive words like d3w
  • dd to delete the line and 2dd to delete to line .number can be changed for deleting the number of consecutive words

How to remove node_modules

  1. Create a .gitignore file in the git repository if it does not contain one

👨🏿‍💻 Software Developer @CGI_Global 🖼 Content Creator. Sharing the mindset and content so you work hard to grow stronger than your past self ☯️