A beginner-friendly repository to learn Git branches and GitHub branching strategies. This project provides step-by-step instructions, code examples, and best practices for working with branches. Whether you're new to version control or looking to enhance your branching skills, this guide will help you navigate through the world of Git branches and collaboration on GitHub.
If you haven't installed Git on your machine, you can download and install it from git-scm.com.
Open a terminal and navigate to the directory where you want to create your project. Run the following commands:
git init
To create a new branch, use the following command:
git branch 'branch_name'
Make sure to add your brannch name.
To switch to the newly created branch, use:
git checkout 'branch_name'
Make sure to add your brannch name.
Alternatively, you can use a single command to create and switch to a new branch:
git checkout -b 'branch_name'
Make sure to add your brannch name.
Make changes to your project files while on the branch.
After making changes, commit them to the branch:
git add .
git commit -m "Your commit message here"
git push origin 'branch_name'
Make sure to add your commit message and brannch name.
Once you're done with changes on a branch, you can merge it back into the main branch (usually main
or master
):
git checkout main
git merge 'branch_name'
Make sure to add your branch name.
-
To view all Git branches:
git branch
-
To delete a Git branch:
git branch --delete 'branch_name'
If you don't have one, create a GitHub account at GitHub.
On GitHub, click the "+" in the top right corner and select "New Repository."
Follow the instructions to create a new repository.
After creating a repository, connect your local repository to the GitHub repository:
git remote add origin 'https://github.com/your-username/your-repository' .
git branch -M main
git push -u origin main
Make sure to add your username and your repository name.
If you want to push branches other than main
, use:
git push origin 'branch_name'
Make sure to add your branch name.
This project is licensed under the MIT License.