How to switch Git branch
- Related posts
How to first commit on Git
I used to GitLab before, and now I have set up Gitea on my Synology NAS server. 💡 tip: This post is a simple guide on how to use Git. First of all, I want to manage to branch: * main: Operation * develop: Development when creating a repository for the first time:
Last time, I explained how to first commit on Git.
Welcome to the Git World
This time, I will explain How to switch a local repository Git branch.
I initially committed my code to the remote main branch, but the main branch is used for production.
So this time, I will create a new branch from remote main branch and switch local repository to that branch.
💡 tip: This post is a simple guide on how to use Git.
Web
- Click to "Branches" menu
- Click to "Create new branch from main" button
- Write name on "Branch Name" label
- Click to "Confirm" button
Local repository
- Move to project directory
- Open terminal
- Check to Local branch
$ git branch
Result:
* main
- Fetch the lastest changes from remote branch
$ git fetch origin
Result:
From https://YourGitURL * [new branch] develop -> origin/develop
- Create a new local branch from remote branch and switch to it
$ git checkout -b develop origin/develop
Result:
branch 'develop' set up to track 'origin/develop'. Switched to a new branch 'develop'
- Check again
$ git branch
Result:
* develop main