Skip to content

San-06/git-workshop

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
Jan 31, 2025
Jan 31, 2025

Repository files navigation

Git Basic Commands

Introduction

Git is a distributed version control system used for tracking changes in source code. Below are the fundamental Git commands to help you get started.


1. Git Configuration

Set up your Git environment:

# Set username
git config --global user.name "Your Name"

# Set email
git config --global user.email "[email protected]"

# Check configuration
git config --list

2. Initialize a Repository

Create a new Git repository:

git init

Clone an existing repository:

git clone <repository_url>

3. Basic Workflow

Check Repository Status

git status

Add Files to Staging Area

git add <file_name>  # Add a specific file
git add .            # Add all files

Commit Changes

git commit -m "Your commit message"

Push Changes to Remote Repository

git push origin <branch_name>

4. Branching in Git

Create a New Branch

git branch <branch_name>

Switch to a Branch

git checkout <branch_name>

OR

git switch <branch_name>

Create and Switch to a New Branch

git checkout -b <branch_name>

OR

git switch -c <branch_name>

List All Branches

git branch

Delete a Branch

git branch -d <branch_name>

5. Merging Branches

Merge a Branch into the Current Branch

git merge <branch_name>

Resolve Merge Conflicts

If there are conflicts, Git will prompt you to resolve them manually. After resolving conflicts:

git add .
git commit -m "Resolved merge conflict"

6. Pulling Changes

Fetch and merge changes from a remote repository:

git pull origin <branch_name>

7. Closing a Feature Branch

Once a feature is merged, delete the branch to keep the repository clean:

git branch -d <branch_name>

If the branch has been pushed to the remote repository, delete it remotely as well:

git push origin --delete <branch_name>

Conclusion

These are the fundamental Git commands that will help you work efficiently with version control. Always make sure to follow best practices like using meaningful commit messages and keeping your branches organized.

About

git workshop

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published