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 mainReview 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.
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 pushIf 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