This document provides a step-by-step guide for students working individually on the git-collaboration-template project. Follow these instructions to learn how to create branches, make changes, and merge them back into the main branch.
- Navigate to the template repository on GitHub.
- Click the green "Use this template" button.
- Select "Create a new repository".
- Give your repository a name (e.g., "my-git-practice").
- Choose whether to make it public or private.
- Click "Create repository from template".
You can work with your repository in two ways:
- Navigate to your newly created repository on GitHub.
- Click the green "Code" button.
- Select the "Codespaces" tab.
- Click "Create codespace on main" or "+" to create a new codespace.
- Wait for the codespace to load - this may take a few minutes.
- Once loaded, you'll have a full development environment in your browser.
-
Navigate to your newly created repository on GitHub.
-
Click the green "Code" button and copy the repository URL.
-
Open your terminal or command prompt.
-
Use the following command to clone the repository:
git clone <repository-url>
-
Change into the project directory:
cd <your-repository-name>
For both Codespaces and Local:
-
Before making any changes, create a new branch for your work. Use the following command, replacing
my-featurewith a descriptive name for your branch:git checkout -b my-feature
For both Codespaces and Local:
- Open the
src/main.pyfile in your code editor. - Make some changes to the script. For example, you can modify the greeting message or add a new function call.
- Save your changes.
For both Codespaces and Local:
-
Stage the changes you made:
git add src/main.py
-
Commit your changes with a descriptive message:
git commit -m "Updated greeting message in main.py"
For both Codespaces and Local:
-
Push your feature branch to the remote repository:
git push origin my-feature
You have two options for merging:
- Navigate to your repository on GitHub.
- You should see a prompt to create a pull request for your recently pushed branch.
- Click "Compare & pull request".
- Add a title and description for your pull request.
- Click "Create pull request".
- Review your changes and click "Merge pull request".
- Confirm the merge by clicking "Confirm merge".
- Optionally, delete the feature branch by clicking "Delete branch".
For both Codespaces and Local:
-
Switch back to the main branch:
git checkout main
-
Pull any remote changes (good practice):
git pull origin main
-
Merge your feature branch into the main branch:
git merge my-feature
-
Push your changes to the remote repository:
git push origin main
For both Codespaces and Local:
-
After merging, you can delete your feature branch locally:
git branch -d my-feature
-
If you used the command line to merge and want to delete the remote branch:
git push origin --delete my-feature
For Local Machine only:
If you merged using a GitHub pull request, make sure to sync your local main branch:
-
Switch to main branch:
git checkout main
-
Pull the latest changes:
git pull origin main
You have successfully completed the individual workflow for this project! You have learned how to create a repository from a template, create branches, make changes, and merge those changes back into the main branch using both GitHub's web interface and command line tools. Continue to explore the exercises provided in the exercises directory to further enhance your Git and GitHub skills.