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

Popular (all time)

Related articles

How to Edit Your WordPress Admin Username and Author Slug via MySQL

In this guide, we’ll walk you through the process of editing both the admin username and author slug using MySQL. Whether you’re looking to strengthen your site's security or simply personalize your author URL, this straightforward method will help you make the changes with ease.

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 Simplify Your Terminal with Custom Bash Aliases

By creating custom shortcuts for your most-used commands, you can save time, reduce errors, and make your terminal experience faster and more enjoyable. In this guide, we’ll show you how to create and manage your own Bash aliases to simplify your terminal workflow and boost your productivity.