Skip to content

Git

Tips and Tricks

Using External Drive as Git Origin

sh
# Open a terminal and navigate to the external drive:
cd /mnt/external_drive

# Create a directory for the bare repository:
mkdir my-project.git
cd my-project.git

# Initialize the bare repository:
git init --bare

# 2. Add the Bare Repository as a Remote in Your Local Repository
# Navigate to your local repository:
cd /path/to/your/local/repository

# Add the remote:
git remote add origin /mnt/external_drive/my-project.git

# 3. Push Changes to the External Drive
# Push your local changes to the remote repository on the external drive:
git push origin main
# Replace main with the name of your branch if it’s different.

# 4. Clone from the External Drive
# If you want to clone the repository from the external drive to another location:

# Navigate to the directory where you want to clone the repository:
cd /path/to/your/desired/location

# Clone the repository:
git clone /mnt/external_drive/my-project.git

Using Remote Computer as Git Origin

sh
# 1. Set Up the Bare Repository on the Remote Computer
# Access the remote computer (e.g., via SSH):
ssh user@remote_computer

# Navigate to the directory where you want to store the repository:
cd /path/to/remote/storage

# Create a directory for the bare repository:
mkdir my-project.git
cd my-project.git

# Initialize the bare repository:
git init --bare

# 2. Add the Remote Repository in Your Local Repository
# Navigate to your local repository:
cd /path/to/your/local/repository

# Add the remote repository using the SSH URL:
git remote add origin ssh://user@remote_computer:/path/to/remote/storage/my-project.git

# 3. Push Changes to the Remote Repository
# Push your local changes to the remote repository:
git push origin main
# Replace main with the name of your branch if it’s different.

# 4. Clone from the Remote Repository
# Navigate to the directory where you want to clone the repository:
cd /path/to/your/desired/location

# Clone the repository:
git clone ssh://user@remote_computer:/path/to/remote/storage/my-project.git

Cheat Sheet

Git add, commit, push

sh
# Reset last commit
git reset HEAD~1

Git Configuration

sh
# Show all configuration settings
git config -l

# or
git config --list

# Edit global configuration
git config --global --edit

# Unset a configuration setting
git config --global --unset setting.name

Resources