Mastering Git and GitHub: A Comprehensive Guide to Setup, Repository Creation, Commits, and More
Table of contents
Introduction
Git
Git is a powerful DevOps tool used for source code management. It is a distributed version control system that tracks changes in the source code during software development. Git enables multiple developers to collaborate on a project efficiently.
GitHub
GitHub is a web-based platform utilizing Git for version control. It provides hosting for software development and facilitates collaboration among developers.
Difference Between Git and GitHub
While Git is a version control system that allows you to manage and track your source code history, GitHub is a cloud-based hosting service that lets you manage Git repositories.
GitHub Features
Some prominent features of GitHub include:
Repository hosting
Pull requests for code reviews
Issues for bug tracking and feature requests, allowing you to state issues and track actions
GitHub Actions for Continuous Integration/Continuous Deployment (CI/CD)
Key Concepts in Git:
Repository (Repo): A database containing all project files and their revision history.
Commit: Refers to changes made to the repository, each with a unique ID (hash #) and a detailed message explaining the commit.
Branch: A parallel version of the repository. Multiple branches help create separate development paths for adding new features or fixing bugs.
Merge: Combining changes from different branches.
Clone: Copying a repository to your local environment to work on.
Setting Up Git
Download and install Git: Git Downloads
Sign up on GitHub: GitHub Sign Up
Download and install Git from the provided link: https://git-scm.com/downloads
Sign up on GitHub using this link: https://github.com/signup
Steps to be followed
Install Git
After installing Git, initialize your git in git bash and configure your username and email. These details will be associated with your commits.
- On your local computer task bar search for git bash and run as administrator.
Configure Git
Open a terminal and set your username and email:
Copy
Copy
bashCopy code git config --global user.name "Your Name"
git config --global user.email "your-email@example.com"
Verify Installation:
Creating a Repository
A Git repository is where your project files and their revision history are stored.
Create a Directory
using a Linux code, we want to Run this command to create a new directory gitlabprojects
Copy
Copy
mkdir gitlabprojects
Run the command below to change to the new directory created.
Copy
Copy
cd gitlabprojects
Initializing a Repository
To initialize a new repository, run the following command
Copy
Copy
git init
This will initialize the empty git repository in the local directory.
-
for confirmation if it has been initialized go to “Document” on your local machine.
Pushing to GitHub
Create a new repository in GitHub. Add a name for it, scroll down and click on create.
Link Local Repository to GitHub:
Copy
git remote add origin <git remote add origin https://github.com/Chiemerie-git/My-Repo.git>
The next thing we will do is create a file and push that file to the remote depository to be sure the link is functional. We will still be using some Linux commands. We can actually run it manually with VScode, but we will still use git bash to get familiar with the interface.
The readme file has been created, we can write some things in the file using the statement nano
Copy
nano readme.md
to be sure the statement was made and injected we will be using “cat” statement
Copy
cat readme.md
Add Files to the Repository: using the code below
Copy
git add readme.md
adding to the branch master you input this code
Copy
git status
Making Your First Commit
Add Files to the Repository:
- Add a new file, e.g.,
README.md
- Add a new file, e.g.,
Commit the File:
Copy
git commit -m "Adding a readme file"
Push Changes:
Copy
git push origin master
Pulling Changes
Fetch and integrate changes from the remote repository:
What is
git pull
?The
git pull
command fetches and integrates changes from a remote repository into your local working directory. It’s essentially a combination of two commands:Copy
git pull origin main
Conclusion
In conclusion, mastering Git and GitHub is essential for any developer looking to enhance their version control and collaboration skills. These tools provide a robust framework for managing code changes, facilitating teamwork, and streamlining the development process. By understanding the key concepts and commands, such as repositories, commits, branches, and merges, developers can efficiently track and manage their projects. Additionally, leveraging GitHub's features like pull requests, issues, and GitHub Actions can significantly improve project management and continuous integration workflows. Embracing these tools not only boosts productivity but also prepares developers for successful collaboration in the tech industry.