Skip to content

This notebook belongs to

Sadat Jubayer

Senior Software Engineer at Premio

If found, please return to hello@jubayer.dev

Vol. 7Seven years of building

Started
January 2020
Everyday tools
TypeScript, Vue, React, Next.js, NestJS, React Native
Education
B.Sc. CSSE, AIUB, 2020
1 min readGit

Useful commands for Git and GitHub

Set up Git, publish your first commit to GitHub, and clone an existing repository to make changes.

Start with a project folder on your computer or an existing repository on GitHub. Install Git, then open a terminal. Git Bash works on Windows.

Configure Git

Set the name and email Git will use for your commits.

git config --global user.name "First Last"
git config --global user.email "you@example.com"

Use your own details. --global applies these settings to repositories you use under your account.

Publish a local project

From your project folder, start a repository on main and make the first commit. Before you push, create an empty repository on GitHub. Leave the README, license and gitignore options unchecked so the remote starts without a commit of its own.

git init -b main
git status
git add .
git diff --staged
git commit -m "First commit"
git remote add origin https://github.com/USERNAME/REPO.git
git push -u origin main

Review the staged files before you commit and substitute your own repository URL. If Git prompts for an HTTPS password, follow GitHub’s HTTPS authentication steps. After the push, your commit appears on GitHub. The -u option sets the upstream branch for future pushes and pulls.

Add stages changes, commit saves a snapshot, and push shares commits. Pull integrates remote changes into an existing branch, and clone makes a new local copy.

Clone a repository and make a change

Copy the clone URL from GitHub and substitute it below. Make your edit after changing into the new folder.

git clone https://github.com/USERNAME/REPO.git
cd REPO
# Edit README.md before running the remaining commands.
git status
git add README.md
git commit -m "Update the README"
git push

If you have push access, the new commit appears on GitHub. Run git log to see the local history or git pull to fetch and integrate updates to your branch.

diagram

Branch, commit, merge

Create a branch from main with git checkout -b, commit your changes, and merge the branch back into main. The example shows a merge commit.