1 π GitHub Setup and Encryption Guide π
Welcome to this friendly guide! π Weβll walk you through setting up Git, configuring GitHub credentials, managing repositories, and securing files with git-crypt
in a Linux environment. Letβs make your GitHub workflow smooth and secure! π
1.1 π οΈ Install Dependencies on Linux
First, letβs install the tools we need to manage repositories and encrypt files. Run these commands to get git
, git-lfs
, git-crypt
, and gnupg
ready! π§
apt-get install git git-lfs
git lfs install
curl -s https://packagecloud.io/install/repositories/github/git-crypt/script.deb.sh | bash
apt-get install git-crypt
sudo apt-get install gnupg
1.2 π€ Configure Username and Email
Set up your Git global configuration with your GitHub username, email, and personal access token. This ensures GitHub knows itβs you! π
username = "your_github_username"
email = "your_github_username_email"
token = "your_github_token"
git config --global user.name "your_github_username"
git config --global user.email "your_github_username_email"
git config --global credential.helper store
git config --global url.https://your_github_token@github.com/.insteadOf "https://github.com/"
git config --global core.editor "nano"
2 π€ Upload to GitHub
2.1 π Clone an Existing Repository
Got an existing repo? Letβs clone it and make your first commit! ποΈ
repo_name = "your_github_repo"
git clone https://github.com/your_github_username/your_github_repo.git
cd your_github_repo
echo "# your_github_repo" >> README.md
git add README.md
git commit -m "first commit"
git push -u origin main
2.2 β¨ Create a New Repository
Want to start fresh? Create a new GitHub repository using the GitHub API and set it up locally. π±
import requests
repo_name = "new-repo-from-colab"
url = "https://api.github.com/user/repos"
headers = {
'Authorization': f'token {token}',
'Content-Type': 'application/json'
}
data = {
'name': repo_name,
'description': 'A repository created from Google Colab',
'private': False
}
response = requests.post(url, headers=headers, json=data)
if response.status_code == 201:
print(f"Repository '{repo_name}' created successfully.")
else:
print(f"Failed to create repository. Status code: {response.status_code}")
print(response.text)
Now, initialize the local repository and push it to GitHub! π
mkdir new-repo-from-colab
cd new-repo-from-colab
git init
git branch -M main
import subprocess
remote_url = f"https://{token}@github.com/{username}/{repo_name}.git"
subprocess.run(['git', 'remote', 'add', 'origin', remote_url], check=True, capture_output=True, text=True)
echo -e "# H1\n## H2\n### H3\n- a\n- b" >> README.md
git add .
git commit -m "my commit"
git push -u origin main
3 π Encrypt Files or Folders Using git-crypt
Keep your sensitive files safe with git-crypt
! Letβs see how to encrypt files and folders. π‘οΈ
3.1 π Initialize git-crypt
Set up git-crypt
in your repository to enable encryption.
git-crypt init
3.2 π Encrypt Individual Files
Encrypt a specific file, like abc.txt
, so only authorized users can read it. π
echo "this is abc.txt, which has been encrypt" >> abc.txt
echo "abc.txt filter=git-crypt diff=git-crypt" > .gitattributes
git add .gitattributes
git commit -m "Add git-crypt configuration for abc.txt"
git add .
git commit -m "Add encrypted abc.txt"
git push -u origin main
3.3 π Encrypt Folders
Encrypt an entire folder, such as do-not-touch
, and all its contents. ποΈπ
mkdir do-not-touch
mkdir do-not-touch/abc-f
echo "this is abc.txt, which has been encrypt" >> do-not-touch/abc.txt
echo "hello 2" >> do-not-touch/abc-f/nhb.txt
echo -e "abc.txt filter=git-crypt diff=git-crypt\ndo-not-touch/** filter=git-crypt diff=git-crypt" >> .gitattributes
git-crypt status -f
git add .gitattributes
git add .
git commit -m "Add git-crypt configuration for abc.txt"
git push -u origin main
4 β Verify Encryption and Export Key
Check which files are encrypted and export the git-crypt
key to share with collaborators or back up securely. π
git-crypt status
git-crypt export-key "your_key_file_location"
5 π Decrypt Files
Clone the encrypted repository and unlock the files using the exported key. ποΈ
sudo apt-get install git-crypt gnupg
git clone https://github.com/your_github_username/your_github_repo.git
cd your_github_repo
gpg --import "your_key_file_location"
git-crypt status
git-crypt unlock "your_key_file_location"
6 π Helpful Tips
- Replace placeholders: Update
your_github_username
,your_github_username_email
,your_github_token
, andyour_github_repo
with your actual GitHub details. ποΈ - Token permissions: Ensure your GitHub personal access token has the
repo
scope for full access. π - Secure key sharing: Share the
git-crypt
key ("your_key_file_location"
) securely with collaborators to allow decryption. π€ - Fix encryption issues: If some files arenβt encrypted properly, run
git-crypt status -f
to stage encrypted versions. π οΈ - Environment: This guide is tailored for Linux environments like Google Colab, but the concepts apply broadly. π§
Happy coding and stay secure! π