Mastering GitHub: Command Line Basics

Mastering GitHub Basics: A Command Line Guide

GitHub, the world's leading platform for version control and collaboration, offers a powerful command line interface (CLI) for efficient workflows. This guide will walk you through the basics of GitHub command line, ensuring you're well-equipped to navigate and manage your repositories like a pro.

Getting Started: Installation and Configuration

Before diving into GitHub command line, ensure you have Git installed on your local machine. You can download and install it from the official Git website. Once installed, configure Git with your name and email using the following commands:

git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"

Setting Up a GitHub Repository

To start using GitHub command line, create a new repository on GitHub.com, then clone it to your local machine using the following command:

Git & GitHub Cheat Sheet 🔥 | Commands, Workflow, Branching & Version Control (Beginner to Pro)
Git & GitHub Cheat Sheet 🔥 | Commands, Workflow, Branching & Version Control (Beginner to Pro)

git clone https://github.com/yourusername/your-repo-name.git

Now, navigate into your local repository:

cd your-repo-name

Understanding GitHub Command Line Workflow

The GitHub command line workflow revolves around three main stages: staging, committing, and pushing. Let's explore each stage with practical examples.

Staging Changes

First, make some changes to your local files. To see the status of your changes, use the git status command. To stage a file, use:

the 12 git commands for windows and macs are shown in this screenshot
the 12 git commands for windows and macs are shown in this screenshot

git add your-file-name

To stage all changes in the current directory, use:

git add .

Committing Changes

Once you've staged your changes, commit them with a meaningful commit message:

git commit -m "Your commit message"

Pushing Changes

Finally, push your committed changes to the remote repository:

the git commands are displayed in different colors and font, including pink, blue, yellow
the git commands are displayed in different colors and font, including pink, blue, yellow

git push origin main

Or, if you're using the master branch:

git push origin master

Branching and Merging

GitHub command line allows you to create, switch, and merge branches effortlessly. To create a new branch:

git checkout -b new-branch

To switch to an existing branch:

git checkout existing-branch

To merge a branch into the current branch:

git merge branch-to-merge

Resolving Conflicts

When merging branches, you may encounter merge conflicts. GitHub command line helps you resolve these conflicts by marking the conflicting sections in your files. Edit the files to resolve the conflicts, then stage and commit the resolved changes:

git add resolved-file
git commit -m "Resolved merge conflict"

Tracking Changes with Logs

To view the commit history of your repository, use the git log command. You can customize the output using various flags, such as:

  • --oneline: Display one-line commit messages
  • --graph: Display a graph of the commit history
  • --all: Display commits from all branches

For example, to display a graph of one-line commit messages from all branches:

git log --oneline --graph --all

Conclusion

Mastering GitHub command line allows you to streamline your workflow, collaborate more effectively, and gain a deeper understanding of version control. With these basics under your belt, you're well-equipped to tackle more advanced GitHub command line topics and become a proficient Git user.

Git & GitHub Cheat Sheet for Beginners
Git & GitHub Cheat Sheet for Beginners
Git Commands Cheat Sheet
Git Commands Cheat Sheet
a green screen with the words github quick start and instructions to use it
a green screen with the words github quick start and instructions to use it
Breaking Down the Basics of Git and Version Control
Breaking Down the Basics of Git and Version Control
The Ultimate Git Commands Cheat Sheet for Developers 🚀💻 #git #command #code
The Ultimate Git Commands Cheat Sheet for Developers 🚀💻 #git #command #code
How to Use Git and GitHub 1: Install Git and Basic Commands
How to Use Git and GitHub 1: Install Git and Basic Commands
Samarpita on Twitter
Samarpita on Twitter
the 12 git commands for windows
the 12 git commands for windows
Important Commands in Git No one will tell you about this 😭🙏   #git #coding
Important Commands in Git No one will tell you about this 😭🙏 #git #coding
9 GitHub Commands Every Beginner Developer Should Know
9 GitHub Commands Every Beginner Developer Should Know
the git workflow and git commands poster
the git workflow and git commands poster
Essential Git Commands: Boost Your Developer Workflow! 🚀💻
Essential Git Commands: Boost Your Developer Workflow! 🚀💻
Clinton Nweze
Clinton Nweze
the 12 git commands for windows
the 12 git commands for windows
Git & GitHub Cheat Sheet
Git & GitHub Cheat Sheet
GitHub for Noobs (1/4) – A Short History
GitHub for Noobs (1/4) – A Short History
Basic git command
Basic git command
Important Git Commands Every Beginner Should Know
Important Git Commands Every Beginner Should Know
GIT COMMANDS
GIT COMMANDS
🔑 Git Key Commands & GitHub Key Features
🔑 Git Key Commands & GitHub Key Features
Git Command Cheat sheet
Git Command Cheat sheet
Git Commands
Git Commands
Top 15 Git Commands Cheatsheet
Top 15 Git Commands Cheatsheet