
Git and GitHub Commands for Beginners: Complete Command Line Guide
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
Command | Description |
---|---|
git status | Check the current status of your repo |
View commit history | View commit history |
git branch | List branches |
git checkout -b feature-name | Create and switch to a new branch |
git merge branch-name | Merge a branch into the current one |
git clone | Clone a repo from GitHub |
Comments
Add new comment