2021-04-18

Git CLI

 18 Apr 2021  Gists

Git CLI

Global configuration:

git config --global credential.helper store
git config --global user.email "[email protected]"
git config --global user.name "Paramdeo Singh"

Push existing Git repository to a remote (e.g. GitLab):

git remote add origin https://gitlab.com/paramdeo/example-repository.git
git add --all
git commit -m "Initial commit"
git push -u origin master

Change URL of remote repository:

# via HTTPS

git remote set-url origin https://gitlab.com/paramdeo/new-repository.git
git remote -v

# via SSH

git remote set-url origin [email protected]:paramdeo/new-repository.git
git remote -v

Undo all unstaged changes since last commit:

git reset --hard

Undo all staged changes made via the git add command:

git restore --staged .

Switch to branch:

git checkout some-branch

Change local branch name (branch must be currently checked out):

git branch -m new-name

Change remote branch name (and push changes):

git push origin :"old-name" "new-name"
git push origin -u new-name

Remove all commits from (master) branch:

git checkout --orphan temp-branch
git add --all
git commit
git branch -D master  # Delete master branch
git branch -m master  # Rename current branch to master
git push -f origin master  # Force push master branch (must un-protect master first)
git gc --aggressive --prune=all     # Clean local Git history
Webmentions & Comments

Copyright © Paramdeo Singh. Built with Jekyll and ☕️ in Guyana. All Rights Reserved.

Last Site Build on Mon, 02 Aug 2021 12:05:40 -0400

1MB Club Badge

Paramdeo Singh Guyana

Riding the wave of consciousness in this treacherous mortal sea.

Technology Design Strategy Literature Personal Blogs