![Git/GitHub Workflow Guide for Beginners](/blog-images/git-github-workflow.webp)
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.
Workflow Checklist
Follow these steps to start working on your teamâs most recent code as your starting point.
Starting Your Session
-
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
.
- Are you in your project folder?
-
Fetch the Latest Changes
- Command:
git fetch --all
- Purpose: Ensures you are aware of the latest changes in the repository.
- Command:
-
Ensure a Clean Slate
- Command:
git status
- Decision Point: Do you have any modified files?
- Yes â See Managing Modified Files.
- No â Proceed to Selecting the Right Branch.
- Command:
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
andgit clean
(use with caution!).
- Command:
Selecting the Right Branch
đż If you're on the wrong branch
- Switch to the
main
ordevelopment
branch:- Command:
git checkout main
orgit checkout development
- Purpose: Ensures you start your new work from the main line of development.
- Command:
Preparing for a Coding Session
-
Update Your Local Repository
- Command:
git pull origin main
orgit pull origin development
- Purpose: Incorporates the latest changes from the central repository into your local repository.
- Command:
-
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.
- Command:
During Your Coding Session
-
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.
- Check Status:
After Your Coding Session
-
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.
- Push Branch:
Submitting Your Work
-
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
ordevelopment
. - Fill out the pull request form with a clear description of your changes.
Final Steps
-
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.