Swiftorial Logo
Home
Swift Lessons
Matchups
CodeSnaps
Tutorials
Career
Resources

Git & GitHub - Basic Git Workflow

Overview of the basic Git workflow

Understanding the basic Git workflow is essential for effective version control. This guide provides an overview of the fundamental steps involved in the Git workflow, including creating a repository, making changes, staging, committing, and pushing changes to a remote repository.

Key Points:

  • The Git workflow consists of several steps: creating a repository, making changes, staging, committing, and pushing.
  • Staging allows you to prepare specific changes for a commit.
  • Committing records the changes in the repository history.
  • Pushing sends the committed changes to a remote repository.

Step 1: Create a Repository

The first step in the Git workflow is to create a new repository. This can be done locally or by cloning an existing remote repository.


# Create a new directory
$ mkdir my-project
$ cd my-project

# Initialize a new Git repository
$ git init
                

Or, clone an existing repository:


# Clone a repository
$ git clone https://github.com/username/repository.git
                

Step 2: Make Changes

Next, make changes to your files using your preferred text editor or IDE. Any changes you make will be tracked by Git.


# Edit a file
$ nano file.txt
                

Step 3: Stage Changes

After making changes, you need to stage them using the git add command. Staging prepares the changes for the next commit.


# Stage a specific file
$ git add file.txt

# Stage all changes
$ git add .
                

Step 4: Commit Changes

Once changes are staged, commit them to the repository using the git commit command. Each commit should have a descriptive message explaining the changes.


# Commit the staged changes
$ git commit -m "Add feature X"
                

Step 5: Push Changes

After committing changes locally, push them to a remote repository to share your work with others or back it up. Use the git push command to push changes.


# Push changes to the remote repository
$ git push origin main
                

Summary

This guide provided an overview of the basic Git workflow, including creating a repository, making changes, staging, committing, and pushing changes to a remote repository. Mastering these steps is crucial for effective version control and collaboration using Git.