Skip to main content

Git Version Control

Commonly used Git commands

Created

October 9, 2022

Modified

October 19, 2026

Configuration

git config --global init.defaultBranch main
git config --global init.defaultBranch
git config --global --list

# set an user name and email that will be associated with each history marker
git config --global user.name "xxx"
git config --global user.email "xxx@example.com"

# set automatic command line coloring for Git for easy reviewing
git config --global color.ui auto
# install `gh` and log in once with gh auth login. Then, from inside any project folder:
pixi global install gh
gh --version
gh auth status
gh auth login
# Creating the repo on GitHub’s website every time is the slow path. Here are the workflows that remove that friction
  • Create a new Git repository and push it to GitHub
git init
git add .
git commit -m "Initial commit"
gh repo create my-project --private --source=. --remote=origin --push

Renmote URL

# Change remote URL
git remote -v # check current remote configuration
git remote set-url origin <new-repository-url> # change remote URL
git remote remove origin # remove remote URL
git remote add origin <new-repository-url> # add new remote URL
## keep your original Git repository but provide a clean version to others,
git archive --format=zip --output=my-project-clean.zip main


# Delete the local branch
git branch -d branch-name     # Use -D to force delete

# Delete the remote branch
git push origin --delete branch-name

# Verify branches are gone
git branch -a                # List all branches

echo "" # create file ""
git status # check
git add # add a file as it looks now to your next commit (stage)
git commit # commit your staged content as a new commit snapshot
### if go to the viam editing mode, i to input, esc to quit, :wq to save and quit
git log # show all commits in the current branch’s history, check versions, q to quit
touch .gitignore
git branch "" # create branch ""
git branch # check branches
git checkout "" # switch to another branch and check it out into your working directory ""
git branch -D "" # delete branch ##
git checkout -b temp # create temporary branch ##
git merage # merge the specified branch’s history into the current one
git clone # retrieve an entire repository from a hosted location via URL
git remote -V # check remove repos information
git push # Transmit local branch commits to the remote repository branch
git fetch # fetch down all the branches from that Git remote
git diff # diff of what is changed but not staged
git pull # fetch and merge any commits from the tracking remote branch
git reset # unstage a file while retaining the changes in working directory
git rm -r --cached . # ignore already added files run

## Go back to a specifi commit
git reset --hard e4098a7

## Pull remote updates and ignore local changes
git fetch origin
git reset --hard origin/your-branch-name

## Change remote URL
git remote -v # check current remote configuration
git remote set-url origin <new-repository-url>
git remote remove origin
git remote add origin <new-repository-url>

## Reset to match remote
git fetch origin
git reset --hard origin/main
#  “remove this file from the repo if it’s already tracked”
git rm --cached config_*

## keep your original Git repository but provide a clean version to others,
git archive --format=zip --output=my-project-clean.zip main

git init
git add .
git commit -m "first commit"
git remote add origin
git push -u origin main

git config --global user.name "" # set an user name that will be associated with each history marker
git config --global user.email "" # set an email address that will be associated with each history marker
git config --global color.ui auto # set automatic command line coloring for Git for easy reviewing
git init #


# 1. Delete the local branch
git branch -d branch-name     # Use -D to force delete

# 2. Delete the remote branch
git push origin --delete branch-name

# 3. Verify branches are gone
git branch -a                # List all branches

echo "" # create file ""
git status # check
git add # add a file as it looks now to your next commit (stage)
git commit # commit your staged content as a new commit snapshot
### if go to the viam editing mode, i to input, esc to quit, :wq to save and quit
git log # show all commits in the current branch’s history, check versions, q to quit
touch .gitignore
git branch "" # create branch ""
git branch # check branches
git checkout "" # switch to another branch and check it out into your working directory ""
git branch -D "" # delete branch ##
git checkout -b temp # create temporary branch ##
git merage # merge the specified branch’s history into the current one
git clone # retrieve an entire repository from a hosted location via URL
git remote -V # check remove repos information
git push # Transmit local branch commits to the remote repository branch
git fetch # fetch down all the branches from that Git remote
git diff # diff of what is changed but not staged
git pull # fetch and merge any commits from the tracking remote branch
git reset # unstage a file while retaining the changes in working directory
git rm -r --cached . # ignore already added files run

## Go back to a specifi commit
git reset --hard e4098a7

## Pull remote updates and ignore local changes
git fetch origin
git reset --hard origin/your-branch-name

## Change remote URL
git remote -v # check current remote configuration
git remote set-url origin <new-repository-url>
git remote remove origin
git remote add origin <new-repository-url>

## Reset to match remote
git fetch origin
git reset --hard origin/main
Back to top