Table of Contents
- Setup Git on apt-based systems ( Debian, Ubuntu )
- Clone a repo
- Pull changes from remote
- Push changes to GitHub
Git Setup on apt-based system
- Install Git if you haven’t done so
sudo apt-get -y install git
2. Generate ssh key (Please do not use SUDO in any of the following commands)
Complete all required steps instructed by the program.
Replace $your_email_on_github with your registered email address on GitHub
cd ~ ssh-keygen -t rsa -C "$your_email_on_github" -f $HOME/.ssh/id_rsa_github
The key / certificate should already been saved at $HOME/.ssh/id_rsa_github. Use the below code to verify
3. Upload the ssh key to your GitHub account
First execute the below command
Copy the output (all output) start with (ssh-rsa) and end with (your email address), open https://github.com/settings/ssh/new (Take you directly to GitHub add ssh key page).
Paste the key into the “Key” block, name it whatever you want and press “Add SSH Key”
4. Go back to the machine, open the following file at a text editor
5. Find the following code
Host github.com User git Port 22 Hostname github.com IdentityFile ~/.ssh/id_rsa
Replace ~/.ssh/id_rsa with ~/.ssh/id_rsa_github
Save the file
Clone a repo
- Find a repo at GitHub
- Find the Green “Clone or Download” button at the right corner
- click on that, make sure the title said “Clone with SSH” (else click on the blue link at right that said “use ssh” to switch)
- Copy the link (format like email@example.com:$user-name/$repo-name.git)
- go back to your
linuxmachine, choose a desiredlocation (cd to it), then paste the command (you might need to enter your ssh key password)
sudo git clone firstname.lastname@example.org:$user-name/$repo-name.git
Create a new local branch
Create a local branch at your machine (replace $branch-name with your desired branch name)
sudo git branch "$branch-name'
Pull changes from the remote repo
Git pull will do a git fetch (fetch code from the repo) and git merge (merge the codes from the remote repo to your local codes)
sudo git pull
Push codes (changes) back to GitHub
Switch to the correct directory (the directory generated / specified when you clone the repo via git)
Use the below command to check if there’s any changes in the local branch
sudo git status
If there’s an instruction that tell you to use “git add”, proceed. Otherwise you have made no changes to the file on this directory.
Use the below command to commit all changes to the remote repo (branch) (Replace $comment with a actual comment)
sudo git commit -a -m "$comment"
Push the commits to remote origin (replace $branch with the branch name on origin/github.com)
sudo git push origin $branch
It’s pushed, check the remote GitHub status.