DEV Community

Abdul Haseeb Mari
Abdul Haseeb Mari

Posted on

Git and GitHub Explained: A Practical Workflow for Beginner Developers

If you're learning software development, understanding Git is one of the most useful skills you can develop.

Many beginners think Git is simply a platform for uploading code. In reality, Git is a version control system that helps developers track changes, maintain project history, and collaborate.

GitHub is a hosting platform where Git repositories can be stored and shared.

Let's understand a practical workflow.

1. Initialize a repository

Inside your project directory, run:

git init
Enter fullscreen mode Exit fullscreen mode

This creates a local Git repository.

Git can now track changes made to files in that project.

2. Check the current status

Run:

git status
Enter fullscreen mode Exit fullscreen mode

This shows which files have changed, which files are untracked, and which changes are staged.

Checking status regularly helps you understand exactly what you are preparing to commit.

3. Stage your changes

To stage a specific file:

git add app.py
Enter fullscreen mode Exit fullscreen mode

To stage all changes in the current directory:

git add .
Enter fullscreen mode Exit fullscreen mode

Staging allows you to choose which changes should be included in the next commit.

4. Create a commit

Run:

git commit -m "Add initial application functionality"
Enter fullscreen mode Exit fullscreen mode

A commit records a snapshot of your staged changes.

Use clear commit messages that explain what you changed.

Examples:

  • Fix login validation
  • Add settings page
  • Improve application startup
  • Update documentation

5. Connect to GitHub

After creating a repository on GitHub, connect your local repository:

git remote add origin YOUR_REPOSITORY_URL
Enter fullscreen mode Exit fullscreen mode

Replace the placeholder with your actual repository URL.

6. Push your code

For a new repository, you can use:

git branch -M main
git push -u origin main
Enter fullscreen mode Exit fullscreen mode

Your local commits are now uploaded to the remote repository.

7. Understand the everyday workflow

A simple development cycle looks like this:

git status
git add .
git commit -m "Describe your changes"
git push
Enter fullscreen mode Exit fullscreen mode

Before committing, review the changes to make sure you are not accidentally including sensitive information.

Never upload passwords, API keys, private tokens, or personal credentials to a public repository.

Bonus: Useful Git commands

Command Purpose
git log View commit history
git diff Inspect unstaged changes
git branch List branches
git switch -c feature-name Create and switch to a branch
git pull Fetch and integrate remote changes
git clone URL Copy a remote repository locally

Final thoughts

Git helps developers work with confidence because changes can be tracked and reviewed over time.

You don't need to memorize every command immediately. Start with the basic workflow and gradually learn more as your projects become larger.

Question: Which Git command do you use most often in your development workflow?

Git #GitHub #VersionControl #Programming #OpenSource #DeveloperTools

Top comments (0)