Introduction
Understanding git has become easier for me when broken down into this four stages.
The working directory is where we write code,amend and delete files,here changes are made but can not be tracked unless they are instructed to commit.
The staging phase is an area where files are modified.
The commit phase is where git takes everything from the staging area and sends it to our local repository,
The push phase is where the saved commits are sent to a remote repository like github.
What is Git?
Git is a version control system or tool used to track changes by developers.
When one installs git it comes with an inbuilt terminal called gitbash
Understanding how Git works.
We start by installing git on my Pc, after installation is done one can check if git is installed by opening a terminal eg powershell on windows and run git --version
How to create folders and files on git bash
First identify where we want the folder to be located
lsis used to list
mkdir "name of the folder" (means make directory)
cd " name of the folder"(change directory)
Readme texts README.mdend with .md since they are written using markdown language.Can use echo,touch or nano commands to write a readme file.
If i want to know the contents of my readme file we use:cat README.md
git config-this is basically telling it my identity
git config --user.name"Esther Karanja"
git config --user.email "my email"git init-this command is used to create or initialize a repository in main/master.
git init maingit status-shows the repository status. This command shows changes and what is happening in git
git statusgit add-stages changes made
git add .this means stage all or one can specify what to be added e.g i want to add only a javascript foldergit add script.jsgit commit-commits records that have been staged in the local git repository.Its like getting a snapshot or memory of the file.
git commit -m "write a commit message"git log-shows a history of all the commits that were made.
git log
git branch should return main
To upload my git folder on github:
Open the github account,create a new repository,click on ssh and copy the link
git remote add origin "paste the ssh key link"
git remote -v
- git push-this command to send commits to the remote repository
git push -u origin mainGit will send the files to my github repository,i can refresh my github and see them
What is github?
Github is a cloud based platform for storing git repositories online.
Just sign up for free,verify via email and your account is created.
git and github are connected using a SSH KEY.
What is a SSH KEY?
SSH stands for secure shell which is a protocol that allows a computer to communicate with another computer over a network.
So how do i generate an SSH key?
ssh-keygen -t ed25519 -C "email signed on github.com"and press enter, the passphase(password authentication)is optional.
This command will generate two keys:example
ed25519
ed25519.pub
The one with .pub is the public key which is the one that we share with github while the other one is a private key which should not be shared.
How to add the SSH Key to Github-open my github account,on settings click on SSH and GPG keys, create a new key and copy the public key that we generated.
How to test the SSH connection
Test before pushing a project using ssh -T git@github.com
In conclusion,i can say that using git and github is easier than i thought,the commands are self explanatory.Basically,i just create my project locally,initialize git,connect my github account and git together using the SSH keys, create a repository,commit and push them to my github account
Top comments (0)