Using Git for PHP Development

GitHub is a platform that allows developers to store their code in the cloud and collaborate. Git is a version control system that tracks file changes. In this article, we will focus on using Git with GitHub.

Create a new Git repository

git init

Display the status of the working directory

git status

Create an empty file in your root directory. Tell Git which files or folders to ignore in your project

touch .gitignore

To stage all files

git add .

To stage a specific file

git add [filename]

To stage a folder use

git add [folderpath]

Add all tracked files and the commit them with your message

git commit -m "first commit"

Fetch changes and download any new commits from the remote repository to your local repository

git pull

Rename the master branch to main

git branch -M main

Add a remote repository

git remote add origin <remote_repository_URL>

Replace '<remote_repository_URL>' with the URL of your remote repository.

For example:

git remote add origin http://github.com/username/repository.git

Push the changes to the remote repository

git push -u origin main

git remote set-url origin http://<token>@github.com/<username>/<repo>

For information about personal access tokens:

http://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens

Run the following to give you the git version number

git --version

Find out the current branch name

git branch

Track a branch's commit history

git log

Verify the remote url

git remote -v

Copies an existing Git repository

git clone http://github.com/username/repository.git

Switch branches

git checkout <branch>

To revert changes to match a specific commit,

git reset --hard <some-commit>
git push --force

Check your configuration settings

git config --list

Configure Git. Let Git know who you are

git config --global user.name "<username>"
git config --global user.email "<email>"

See all possible commands

git help --all

Sign up for an account on GitHub:

http://github.com

For more information:

http://git-scm.com

Learn

Related articles

Getting Started with React

In this guide, we will cover the basics of setting up a local development environment, starting a simple React project, and the basics of how it works.

How to Create Bash Aliases

This tutorial demonstrates how to use the alias command to create personalized shortcuts, which can help you save time and feel less frustrated.

How to Connect to MySQL with Laravel

In this guide, you will learn how to connect your Laravel application to your MySQL database.

How do you change the default SSH Port on CentOS Stream 9?

Changing the default SSH port adds an extra layer of security by reducing the risk of your password being cracked from a brute force attack.

What is Inheritance in PHP?

In this tutorial we will explain inheritance in PHP, a mechanism that allows a child class to inherit properties and behaviors from a parent class.

How to Allow Remote Access to MySQL

In this guide, we will show you how to how to setup a user account and access a MySQL server remotely on a Linux system.