What is Git?
Git is version control system that helps you keep track of changes in made to your code. Instead of saving many copies of the same project, Git record each changes and store it as part of the project history.
with git you can always go back to an earlier version of your code if something goes wrong. Git works locally on your computer and does not need internet to track changes.
Why version control is important
version control is important for several reasons
- it helps you avoid loosing your work
- You can see what changes were made and when
- It allows Multiple people to work on the same project
- You can easily fix mistakes by going back to previous version In real software project, Version is necessary because code change is always changing.
Git and GitHub Difference
Git and GitHub are not the same thing
- Git is the tool that track and changes your computer
- GitHub is an online platform where you store and share your Git project you use Git commands to send your code to GitHub or get code from GitHub
Seting up Git on your computer
Before using Git, you need to make sure it is installed and configured.
Check Git version
To confirm Git is installed:
git --version
Configure your Name and Email
Git uses this information to track who made changes.
git config --global user.name "joseph"
git config --global user.email "joseph@gmail.com"
To confirm the configuration :
git config --global --list
Setting up HHS
SSH allow you to connect to GitHub securely without entering your password every time.
Generate HHS key
ssh--keygen -t ed25519 -C joseph@gmail.com"
Press enter to accept the default file location.
Start the HHS agent
eval "$(ssh-agent -s)"
Add SSH key
ssh-add ~/.ssh/id_ed25519
Copy the public key
cat ~/.ssh/id_ed25519.pub
Copy the output and add it to GitHub → setting → SHH → and GPG key.
How to push GitHub code
First, open your project in the terminal
Step one
Step 1: Initialise Git
git init
Step 2: Check file status
git status
Step 3: Add File
git add.
step 4: Commit changes
git commit -m "My first commit"
Step 5 : Connect to GitHub Repository
git remote add origin https://github.com/username/repository-name.git
Step 6: Push the code
git push -u origin main
your code will now appear on GitHub
How to pull code from GitHub
pulling means getting the latest version of the project from giHub
git pull origin main
this is usefully when working others or when switching devices
How to track changes using Git
To see changed files
git status
To see what exactly changed.
git diff
To view commit history
git log
This commands help you understand how your project has changed over time
conclusion
Git is very important tool for developers. It helps you manage your code, track changes, and work with others.
Top comments (0)