Getting Started with Version Control: 2 — Necessary Git & GitHub Commands

 


🔧 1. Setting Up Git

Before we jump into Git commands, we must set up our Git environment:

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

This configures your identity for all Git repositories on the system. ​

📁 2. Initializing a Repository

Here’s how to start tracking a project with Git:

mkdir my-project cd my-project git init

This will create a new Git repository in your project directory. ​Stack Overflow

📥 3. Clone a repo

To develop an already-existing project:

git clone https://github.com/username/repository.git

This command is to clone the repository on your local computer. ​

📝 4. Tracking Changes

You can see the status of files after editing them:

git status

To stage changes for commit:​

git add filename # For one file
git add. # Stages everything found in the directory

💾 5. Committing Changes

To save your staged changes:

git commit -m "Your commit message here"

This saves your changes to be part of the history of the repository. ​

🌿 6. Branching and Merging

To make and checkout a new branch:

git checkout -b new-feature

Make some changes in the new branch and merge it back to the master branch:​

git checkout main && git merge new-feature

🔄 7. Pushing and Pulling

Steps to push local commits to GitHub

git push origin main

Fetching and merging changes from GitHub

git pull origin main

📜 8. Viewing Commit History

For the history of the commits:

git log

Print out all of the commits on the current branch. ​

These commands form the basic building blocks of doing effective version control with Git and GitHub. In the next chapter, Git Workflow, you can start working with Seept for Part 3 and read Part 1 




Getting Started with Version Control: 2 — Necessary Git & GitHub Commands Getting Started with Version Control: 2 — Necessary Git & GitHub Commands Reviewed by Mady on April 13, 2025 Rating: 5

No comments:

Powered by Blogger.