How To Use Git CLI
pkg update && pkg install openssh git gh -y
sudo apt update && sudo apt install ssh git gh -y
Configure your username with this command
git config --global user.name "username"
Now configure your email with this command
git config --global user.email "[email protected]"
- The username and email must match to your github account
- The username may be case sensitive
mkdir -p ~/.ssh
ssh-keygen -t rsa -b 2048 -C "[email protected]" -f ~/.ssh/id_rsa
You will be asked for some info fill them according to your choice or just press enter and enter again until it finishes.
As we have created the ssh-key now its time to add that key into our github account by which we can authenticate to account by using CLI.
To do this the first steps is that we need to copy the public key of ssh for that we will be using a command
cat ~/.ssh/id_rsa.pub
Now copy the text (key) shown on the to the clipboard and follow the next steps
- Go to browser and log in to your github account
- Click on Setting
- Click on SSH and GPG Keys
- Click on "New SSH key"
- Now paste the ssh key in the "key" section you can choose a title whatever you want and the Key type must be set to "Authentication Key" Now click on "Add SSH key"
gh auth login
move to your directory where you have stored your project and follow the steps
First we will initialize that directory
git init
Now add all the files and folders to git
git add .
Then we have to commit
git commit -m "Initial commit"
We can configure our branch, by default it is master branch
You can check branch by typing this command
git branch
To rename the branch to main type
git branch -M main
After all this we have to add the github repo
git remote add origin https://github.com/username/repo.git
The final step is to push the local git to github repo
git push -u origin main
Now if you have changed anything to your file and you want to update it on the repo for that we don't have to do these all thinkgs this was for the first time.
Suppose we have changed any file now follow the steps.
Fist of all the add the current file to git
git add .
Then we need to commit it with a reason!
git commit -m "Updated README.md"
The final step is to push
git push