Git
Simple workflow with Git
- Clone the remote repo from Github as origin (default name of local cloned repo)
- Edit the files in the local repo
-
Add the changes into the Stage
Bash 1
git add . # add all changes into the Stage
-
Commit the changes in the local repo
Bash 1
git commit -m "message" # commit the changes in the local repo and indicate the changes with the variable message
-
Push the local repo to the remote repo in Github
6. Combine the current changes into the last commitBash 1
git push origin main # push the local repo to the main branch in the remote repo
SinceBash 1
git commit --amend -m "message"
--amend
rewrites history, the commit ID will change. If you've already pushed the last commit to a remote repository, you'll need to useforce push
this timeOther CommandsBash 1
git push origin main --force
Bash 1 2
git remote # show the name of the local cloned repo git status # show the editing status of Stage, local repo
Join and work in other's project
🔐 Setting Up GitHub SSH Access on Ubuntu
1. Generate a New SSH Key
Open your terminal and run:
Bash | |
---|---|
1 |
|
- Replace
"your_email@example.com"
with your GitHub email address. - Press
Enter
to accept the default file location. - Optionally, set a passphrase for added security.
2. Start the SSH Agent and Add Your Key
Start the SSH agent in the background:
Bash | |
---|---|
1 |
|
Add your SSH private key to the agent:
Bash | |
---|---|
1 |
|
3. Add the SSH Key to Your GitHub Account
Copy the contents of your public key to the clipboard:
Bash | |
---|---|
1 |
|
Then, follow these steps:
- Log in to your GitHub account.
- In the upper-right corner, click your profile photo, then click Settings.
- In the left sidebar, click SSH and GPG keys.
- Click New SSH key.
- In the "Title" field, add a descriptive label for the new key.
- Paste your public key into the "Key" field.
- Click Add SSH key.
4. Test Your SSH Connection
Verify that your SSH key is correctly set up:
Bash | |
---|---|
1 |
|
You should see a message like:
Bash | |
---|---|
1 |
|
5. Clone a Repository Using SSH
Now, you can clone repositories using SSH:
Bash | |
---|---|
1 |
|
- Replace
username
with the repository owner's GitHub username. - Replace
repository
with the name of the repository you want to clone.
By following these steps, you've configured SSH authentication with GitHub on your Ubuntu system. This setup allows you to interact with GitHub repositories securely without entering your credentials each time.