Stop Using git checkout
Git 2.23 introduced two commands that replace the two different jobs git checkout used to do: git switch — change or create…
Feature branches act as a container for new functionality you're adding or changes you're making to a project while keeping your main branch untouched. They help keep your modifications organized and separated from the main working code base (usually the "main" or "master" branch) until you're ready to integrate them.
git checkout -b <branch-name><branch-name> should be descriptive, based on the feature you're developing, e.g., add-user-authentication.git checkout -b add-user-authenticationgit checkout -b <branch-name> command and follow the steps below.git commit <file-name> -m "<descriptive-message>"<file-name> refers to the files you've modified, e.g., file.php) and commits them with a message describing what you've done.git commit file.php -m "Add user authentication methods"git push -u origin <branch-name>-u flag sets the upstream, meaning future pushes on this branch can just use git push without additional arguments.git push -u origin add-user-authenticationgit checkout main), pulling the latest changes (git pull), and then merging them into your feature branch (git checkout <branch-name> followed by git merge main).git push origin --delete <branch-name>) and your local repository (git branch -d <branch-name>).git branch or git branch --listgit branch without arguments lists all branches in your local repository. The branch marked with an asterisk (*) is the branch you're currently on. This doesn't show branches on the remote repository; for that, you would use git branch -r.git checkout <branch-name><branch-name>. Ensure you've committed or stashed changes in your current branch before switching, or you might face conflicts.develop branch and want to switch back to the main branch, you would type git checkout main.git branch --show-current or git symbolic-ref --short HEADgit branch --show-current command (available since Git version 2.22) displays the name of the current branch. Alternatively, git symbolic-ref --short HEAD provides the same information; these commands are helpful if you're scripting or need the branch name for automation.git checkout -b <new-branch-name>git checkout -b new-featuregit stashgit stash to save your changes temporarily. You can come back to them later by using git stash pop after you've switched back to your original branch.git pull origin <branch-name>git pull origin mainCreating a new branch based on another branch (other than the one you're currently on) comes handy when you want to extend or add features to an existing feature.
Here's how you do it:
git checkout <base-branch-name><base-branch-name> with the name of the branch you want your new branch to be based on. This could be any existing branch like develop, feature-x, etc.git checkout anotherbranch
anotherbranch branch.git pull origin <base-branch-name>git pull origin anotherbranch
anotherbranch is up-to-date with anotherbranch on the remote repository (origin).git checkout -b <new-feature-branch>git checkout -b feature
feature based on the current state of anotherbranch.git branch --show-currentfeature, indicating that you're now on the feature branch.Now, you can start working on your new feature. The new branch contains the history of the base branch, plus any changes you're about to make.
Give Vroni a GitHub issue, bug report, spec, or rough idea. It reads the repo, plans the change, writes code, runs checks, and works toward a review-ready pull request.
Take a look at vroni.com