Check out My Repository
Table of Contents
Introduction
Setting Up Git
- Installation
- Configuration
Creating a Repository
- Initializing a Repository
- Cloning a Repository
Basic Git Commands
- Checking Status
- Adding Files
- Making Commits
- Pushing Changes
- Pulling Changes
Introduction
Git and GitHub have become essential tools for developers worldwide. Git is a version control system that tracks changes in source code, while GitHub is a web-based platform for hosting Git repositories. Mastering Git and GitHub is crucial for modern software development and devops. This guide will walk you through setting up Git, creating a repository and using the basic commands like commits, pushing and pulling.
Setting Up Git
To get started with Git,
- Click download to download and install.
- Choose your local computer OS. For windows, choose the appropriate for your configuration and install.
- Sign up on GitHub to register a GitHub account.
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 Username. Run the command below personalizing the username and press enter.
git config --global user.name "Your GitHub username"
-
Configure email. Run the command below personalizing the email and press enter.
git config --global user.email "your github email address"
Creating a Repository
A Git repository is where your project files and their revision history are stored.
- Run this command to create a new directory called gitlab.
mkdir gitlab
- Run the command below to change directory
cd gitlab
Initializing a Repository
To create a new repository, run the following command
git init
This will initialize empty git repository in the local directory.
- To open a new visual studio code, run the following command and press enter.
code .
You need to have a code before you can carry out any other command.
- On the Visual studio code create a .html file. On the menu, click on the 3 dot select terminal and then new terminal.
- On the terminal, run git commands like check status, add, commit, push and pull.
Checking Status
git status
Adding Files
Add your file to the staging area.
git add filename
- To add all changes:
git add .
Making Commits
Commits are snapshots of your project at a given point in time. Once your changes are staged with the add command, commit them with a message:
git commit -m "Your commit message"
Pushing Changes
Pushing command sends your commits to a remote repository, like GitHub. Hence, the remote repository has to exist first before a push command can take effect.
Creating Remote Repository GitHub
- go github.com and sign in
- click on + to add new repository
- Give it a name.
- choose public or private
- Add README file for your documentation
- Click create repository
- go to code and copy the repository url.
- connect the repository to the local machine. use the following command.
git remote add origin repo url
- Push changes
git push origin master
- sign in to GitHub when prompted and authorize git ecosystem. This is only applicable when you are pushing for the first time.
-
Go back to GitHub and notice the file is now in GitHub.
-
add a readme file on visual studio code. Afterwards do git add, git commit and git push.
Pulling Changes
Pulling fetches and merges changes from the remote repository to your local repository.
- Edit any of the file on GitHub, commit changes
- On your terminal, type the pull command below and notice the changes now reflect.
git pull origin master
Check out My Repository