Git/GitHub Workflow Guide for Beginners

Git/GitHub Workflow Guide for Beginners


git github version control beginner

This guide provides a practical checklist for beginners to navigate through a typical coding session using Git and GitHub, emphasizing a workflow where each team member works on their own branches and merges changes into a central branch via pull requests.

💡 Important: Always work on your own branch to avoid conflicts. Two people should never edit the same branch simultaneously.

Workflow Checklist

Follow these steps to start working on your team’s most recent code as your starting point.

Starting Your Session

  1. Check Your Project Folder

    • Are you in your project folder?
      • Yes → Proceed to the next step.
      • No → Navigate to your project folder using cd path/to/your-project.
  2. Fetch the Latest Changes

    • Command: git fetch --all
    • Purpose: Ensures you are aware of the latest changes in the repository.
  3. Ensure a Clean Slate

Managing Modified Files

📁 If you have modified files
  • Keep Modified Files:
    • On Your Own Branch? → Commit to your current branch.
    • On a Shared Branch? → Create a new branch for your changes.
  • Delete Modified Files:
    • Command: git reset --hard and git clean (use with caution!).

Selecting the Right Branch

🌿 If you're on the wrong branch
  • Switch to the main or development branch:
    • Command: git checkout main or git checkout development
    • Purpose: Ensures you start your new work from the main line of development.

Preparing for a Coding Session

  1. Update Your Local Repository

    • Command: git pull origin main or git pull origin development
    • Purpose: Incorporates the latest changes from the central repository into your local repository.
  2. Create a New Branch to Start Coding

    • Command: git checkout -b feature/my-new-feature
    • Purpose: Starts a new branch for your work, ensuring isolation from the main codebase.

During Your Coding Session

  1. Commit Your Changes Regularly

    • Check Status: git status to view changes.
    • Stage Changes: git add . to stage all modified files.
    • Commit Changes: git commit -m "Add a descriptive commit message" to save your progress.

After Your Coding Session

  1. Push Your Branch and Prepare for Pull Request

    • Push Branch: git push -u origin feature/my-new-feature
    • Prepare Pull Request: Ensure your branch is ready to be merged into the main codebase by reviewing your changes and comparing them to the project’s contribution guidelines.

Submitting Your Work

  1. Create a Pull Request on GitHub

    • Navigate to the repository’s pull requests tab.
    • Click “New Pull Request” and select your branch to merge into main or development.
    • Fill out the pull request form with a clear description of your changes.

Final Steps

  1. Review and Merge

    • Work with your team to review your pull request.
    • Once approved, merge your changes into the main codebase.

Conclusion

Embracing the Git/GitHub workflow is an essential step in the journey of any software developer. By following the structured steps outlined in this guide, you’ll streamline your development process and foster better collaboration within your team. Remember, mastery comes with practice, so don’t hesitate to experiment with different commands and more complex workflows as you grow more comfortable with Git and GitHub. As you continue contributing to projects, you’ll find these tools indispensable for managing your code, tracking changes, and collaborating effectively.

© 2024 Anderson Marques

  • fm-anderson