Version Controlling
Git
- Git is used to track versions of our code & was created by Linus Torvalds
- As git is a software we need to have it installed on our system, Linux comes with it preinstalled
- We can check for git installation using this command:
git --version
Git Workflow & Commands
- Some folders includes things like /node_modules & files like
.envfile that contains our credentials
- There’s a special
.gitignorefile that we can use to untrack files & folders
- A special
README.mdfile contains general information of our project, which is shown differently in our GitHub repository
- To track changes of any folder we first have to initialize it with git by running:
git init
- Then we need to add it to the staging index by running:
git add .
- And then we can commit our changes:
git commit -m "Initial commit"(m for message)
- Then we can push it to our remote repo by running:
git push origin main
- For this our remote should be connected by running:
git remote add origin https://github.com/username/repo.git
- To disconnect our remote repo for some reason we can do:
git remote remove origin
- To clone from a remote repo:
git clone https://github.com/username/repo.git
Authentication
- We have to authenticate our computer with GitHub if we want to perform push operation to our remote
- There are multiple ways to authenticate but the simplest one is to use VS Code’s built in authentication
- We can also utilize using SSH keys or a PAT token
SSH Keys
We need to perform these steps to authenticate our GitHub account. Using VS Code directly helps us to skip these steps
- Read official docs here
- We use
sshto generate cryptographic keys which helps us create connection between two computers
- We generally buy a server from a cloud hosting company such as DigitalOcean and generate
SSHkeys and put the public keys on the server then connect it with our system using the private keys
Generating SSH Keys
This is not important if we have already authenticated GitHub using VS Code
- This will generate a public and a private key inside the
homeoruserdirectory
- The public key ends with a
.pubwe need to upload this to our GitHub
GitHub > Settings > SSH and GPG Keys > Add new SSH Keys
- After this we need to add it to the SSH agent
eval "$(ssh-agent -s)”ssh-add ~/.ssh/id_ed25519
- Now run this command:
ssh -T git@github.com
- And to clone a Git repository use the SSH link
🙇🏻 git commit -m “uncle linus torvalds”