Git may initially seem difficult to someone who is unfamiliar with software development.
Although they sound scary, these terms are used in regular developer operations including:
Pull code
Push code
Track changes
I'll explain Git in an easy-to-understand manner in this post so you can manage your code.
What Version Control Is and Its Importance
Version Control makes it easier to monitor changes made to files over time. Git maintains a complete history of your project.
Importances of Git and Version Control In Development
- Collaborate on assignments with peers without overwriting
- Look into projects to find out who improved them
- Revert to previous forms of work
Installing Git and Set up Procedures
For Windows users:
- Download Git
- First, make sure Git is installed:
git --version
Git is installed, and a version number is displayed.
Set up your identity through:
git config --global user.name "Your Name"
git config --global user.email "youremail@example.com"
Connecting Git to your Github Account
After you have set up your identity, proceed to generate an SSH key
# Create a new SSH key
ssh-keygen t ed25519 -C "your email"
# Press ENTER to define default location
# Copy the key to be used later on
# For Windows users
C:\Users\YOUR_USERNAME\.ssh\id_ed25519.pub
Connect SSH key to Github
- Go to Github
- Click on your profile on the top right, choose settings
- On the left side of the page, select SSH and GPG keys
- Click on "New SSH key"
- The key that you had earlier copied, paste it on the pop up and give it a name
- Click add SSH key Test your Generated key
ssh -T git@github.com
An authentication key is generated that confirms the connection.
Tracking Changes: Add and Commit
These are the ways in which Git tracks changes through committing and staging.
A. Add Files to the Staging Area
Git detects when you create or edit files, but it does not immediately save them.
In order to stage a file:
git add filename.txt
To stage every work that is in progress:
git add .
B. Commit changes
A commit is a snapshot of your project at a specific point in time.
git commit -m "Add SQL project structure"
Push and Pull Code
For you to better understand the push and pull concept, it is best to introduce the aspect of repositories which are divided into either local or remote repository.
- Local REPOSITORY
This lives on your PC.
- Remote REPOSITORY
This lives on a different platform like Github.
Code is written locally, committed, and then pushed to the remote repository for public viewing.
Connecting to a Remote Repository
After creating a repository on Github:
git remote add origin https://github.com/username/repository-name.git
Check that the connection works:
git remote -v
Pushing Code to Github
Once you upload any project your local repository commits to the remote repository:
git push origin main
- origin is the remote name
- main is the branch name Subsequently, your code will appear on Github.
Pulling Code from a Remote Repository
In the event that changes were made on GitHub (by your collaborator on a project), pull them to your local machine:
git pull origin main
This keeps your local project up to date.
Git and Github are key basics in your coding journey.
Embrace their capabilities and diversities and your journey will be unstoppable 🚀
Top comments (0)