GitHub-for-beginners

Git and GitHub Commands for Beginners: Complete Command Line Guide

  • Profile picture of Mcs
  • by Mcs June 30, 2025

Mastering GitHub from the Command Line: Essential Git Commands for Beginners

If you’re just starting out with Git and GitHub, the command line might feel a little intimidating. But once you get the hang of a few basic commands, you'll be collaborating like a pro. In this post, we’ll walk through some of the most essential Git and GitHub commands every developer should know.

What You’ll Learn:

  • How to set up Git
  • How to create a local repository
  • How to connect your repo to GitHub
  • How to push, pull, and manage changes

Setting Up Git

Before using Git, make sure it’s installed(How to install Git). Then configure your identity:

git config --global user.name

git config --global user.email

You can also check your setup with:

git config --list

Creating a New Git Repository

Navigate to your project folder and initialize Git:

 

git init

Tracking Files

Add your project files to the staging area:

git add .

Then commit your changes with a message:

git commit -m "Initial commit"

Connecting to GitHub

Create a new repository on GitHub. Then link your local repo to GitHub:

git remote add origin https://github.com/your-username/your-repo.git

Push your local changes to GitHub:

git push -u origin main

Replace main with master if your default branch is named that.

Keeping Your Repo in Sync

To get changes from GitHub:

git pull origin main

To push local commits:

git push origin main

Common Git Commands Cheat Sheet

CommandDescription
git statusCheck the current status of your repo
View commit historyView commit history
git branchList branches
git checkout -b feature-nameCreate and switch to a new branch
git merge branch-nameMerge a branch into the current one
git cloneClone a repo from GitHub

Comments

Add new comment

Restricted HTML

  • Allowed HTML tags: <br> <p> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id> <cite> <dl> <dt> <dd> <a hreflang href> <blockquote cite> <ul type> <ol type start> <strong> <em> <code> <li>
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.