Git and GitHub: A Comprehensive Guide
Otitoju Mercy
Posted on September 3, 2024
What is Git?
Git is a distributed version control system used to track changes in files, typically source code. It allows multiple developers to collaborate on a project by managing and recording changes over time. Git is widely used because of its speed, efficiency, and flexibility, making it an essential tool in modern software development.
What is GitHub?
GitHub is an online platform for storing, sharing, and collaborating on code using Git. With GitHub, you can store your code online, collaborate with other developers, and track changes over time, all in one place.
Basic Git Command
Here are some basic Git commands:
-
git init
: Start a new Git repository in your current directory. -
git clone <repository-url>
: Download an existing repository to your local machine. -
git add <file>
: Stage changes to be included in the next commit. -
git commit -m "message"
: Save staged changes with a commit message. -
git status
: Show the current status of your working directory and staging area. -
git log
: View the history of commits. -
git push
: Upload local commits to a remote repository (like GitHub). -
git pull
: Download and merge changes from a remote repository. -
git branch
: List all branches or create a new branch. -
git checkout <branch>
: Switch to a different branch. -
git remote add origin [repository link]
: Connect the local folder to the GitHub repository. -
git push -u origin main
: Push code to the 'main' branch on GitHub.
Before the end of the blog will be able to set up git on window's, creating a respository , making commits, pushing and pulling.
Setting up Git on Windows.
Install Git: Download from https://git-scm.com/book/en/v2/Getting-Started-Installing-Git website, run it, and follow the installation instructions.
Configuring Git:After installation,Open Gitbash as ADMINISTRATOR,and run the following Git command :
- git version -TO KNOW THE GIT VERSION.
- git status -TO KNOW GIT STATUS IF THERE IS ANY PENDING CHANGE.
- git config --global user.name githubusername -LIKE LOGIN USERNAME.
- git config --global user.mail githubemail -LIKE LOGIN EMAIL ADDRESS
- mkdir filename -TO CREATE FOLDER IN FILE EXPLORER
- cd filename -TO ENTER INTO A PARTICULAR FILE NAME
- git init -TO MAKE A FOLDER A GIT REPOSITORY SO AS TO HAVE ACCESS TO GIT COMMANDS
- code . -TO TRANSIT INTO VS CODE
- This takes you to Visual Studio Code.
- Click on the icon to create a file.
- Name the file
index.html
.
- Paste your HTML code into it,
- Click on the three dots at the top,
- Click on Terminal, then New Terminal.
In the terminal type the following command;
git add <file>:
Add a file to the staging area.git status:
Show the status of changes.
Creating a Repository.
Repository (often abbreviated as "repo")serves as a structured place where various types of digital resources are stored, managed, and accessed Creating a repository on GitHub is a straightforward process. Here’s a step-by-step guide to get you started:
- Go to GitHub,Log in to your GitHub account.
- Click the "+" icon in the top right corner of the page. Select "New repository" from the dropdown menu.
- Repository Name: Enter a name for your repository.
- Description: (Optional) Provide a brief description of your repository.
- Private or Public: Choose people that can see this repository.
- Add a README file.
- Click the "Create repository" button at the bottom of the page.
Making a Commit.
A commit is a record of changes made to the files in a repository. It represents a snapshot of the project at a particular point in time. Making a commit in Git involves a few straightforward steps. Here’s a step-by-step guide to help you through the process:
- Use the git commit command followed by the -m flag and your commit message in quotes.
Pushing and Pulling.
Pushing is the process of uploading your local commits to a remote repository. This updates the remote repository with changes made locally. Here is the command used for pushing changes:
- Copy The Link Of the remote Repository.
Issue a git push command using url of the remote repository:
- git push master: Pushes changes to a specific remote and branch.
If you are Pushing for the first time, you will be taken to GitHub sign-in and authorization.
- Go to GitHub, to see the recent Push
- Type
git commit -m "adding readme.md"
, To check the readme file, go to your GitHub account, refresh, and click onreadme.md
to see the message earlier typed when you created the readme.md file.
- To edit click on the edit icon after editing your text, click on Commit Changes
Pulling in Git is the process of updating your local repository with changes from a remote repository .This command helps keep your work synchronized with your team's changes, ensuring you're always working with the latest version of the project.
- Go to Visual Code terminal, type this git pull origin master
"Congratulations on successfully setting up Git on Windows! You've mastered the essentials of version control by creating a repository, making commits, and learning how to push and pull changes. This is a solid foundation that will serve you well in your development journey. Great job!"
Posted on September 3, 2024
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.