Github Commands every developer needs to know

Github Commands every developer needs to know

Cheatsheet

·

1 min read

Below are some of the important GitHub commands we need to know in software development.

Clone a repository

git clone <repo-url>
# git clone https://github.com/<username>/<repo-name>.git

Add upstream repo

git remote add <upstream-repo-alias> <repo-url>
#git remote add upstream https://github.com/<username>/<repo-name>.git

Set repo origin

git remote set-url origin <repo-url>
git remote set-url origin https://github.com/<username>/<repo-name>.git

Get existing repos

git remote -v

Remove existing repo

git remote rm <repo-alias>

Fetch repo origin

git fetch origin

Revert the last commit

git reset --soft HEAD^

Hard Reset

git reset --hard origin/master

Create new branch(You can also create directly from GitHub repository)

git checkout -b <branch-name>

Checkout existing branch

git checkout <branch-name>

Branch status

git status

Push the committed changes

git push origin

Pull the latest changes from the forked branch

git pull

Pull the latest changes from the upstream branch

git pull <upstream-repo-alias> <branch-name>