

It allows you to work on multiple features or fixes simultaneously, without affecting the main branch. To switch between branches, use the git checkout command followed by the branch name: git checkout įor example, to switch back to the main branch (usually called “master” or “main”), run: git checkout main ConclusionĬreating local and remote Git branches is an essential skill for developers working with version control. For example, if your branch is named “feature-login,” run: git push -u origin feature-login 5. This command pushes your local branch to the remote repository and sets up a tracking relationship between the local and remote branches. Use the following command: git push -u origin Now, you’re ready to push your local branch to the remote repository. Replace with the URL of your remote repository. Next, link your local repository to the remote one by running: git remote add origin If you’re using GitHub, GitLab, or Bitbucket, create a new repository on their platform. To do this, first, make sure you have a remote repository set up. In order to share your local branch with others or to work on it from another computer, you need to push it to a remote repository. git commit -m "Your commit message here" 4. To stage and commit your changes, use the following commands: git add. Once you’ve created your new branch, you can start making changes to your project files. For example, if you want to create a new branch named “feature-login,” run: git checkout -b feature-login 3. No more git push -set-upstream origin test & git push again Bye. This command creates a new branch and switches to it immediately. 0) sets the upstream tracking to the corresponding branch. Replace with a descriptive name for your new branch. To create a new local branch, use the following command: git checkout -b git folder that contains the repository’s metadata. This command initializes a new Git repository in your project directory, creating a hidden.

To initialize a new local Git repository, open a terminal, navigate to your project directory, and run the following command: git init Setting up the local Git repositoryīefore creating branches, you need to have a local Git repository.
