How To Use GitHub?

Create a GitHub account at https://github.com/

Install Git from https://git-scm.com/

Configure Git:

`git config –global user.name “Your Name”`

`git config –global user.email “you@example.com”`

Create a repository on GitHub:

Click New repository

Enter a repository name

Choose Public or Private

Optionally add a README

Clone the repository:

`git clone https://github.com/USERNAME/REPO.git`

`cd REPO`

Check status:

`git status`

Add files:

`git add .`

or `git add path/to/file`

Commit changes:

`git commit -m “Your commit message”`

Push to GitHub:

`git push origin main`

If your branch is `master`, use `git push origin master`

Create and switch to a new branch:

`git checkout -b feature-branch`

or `git switch -c feature-branch`

Merge a branch:

`git checkout main`

`git merge feature-branch`

Pull latest changes:

`git pull origin main`

Fetch updates without merging:

`git fetch origin`

View commit history:

`git log`

View differences:

`git diff`

`git diff –staged`

Create a pull request:

Push your branch to GitHub

Open the repository on GitHub

Click Compare & pull request

Resolve merge conflicts (local):

Edit conflicted files

`git add .`

`git commit`

Remove a local branch:

`git branch -d feature-branch`

Delete a remote branch:

`git push origin –delete feature-branch`

Add a remote if needed:

`git remote add origin https://github.com/USERNAME/REPO.git`

List remotes:

`git remote -v`

Create a new repository from an existing folder:

`cd /path/to/project`

`git init`

`git add .`

`git commit -m “Initial commit”`

`git branch -M main`

`git remote add origin https://github.com/USERNAME/REPO.git`

`git push -u origin main`

Suggested for You

Trending Today