Create a dev Branch from Local main and Push It to Remote with Git
This guide walks through the step‑by‑step Git commands needed to ensure your local repository is up‑to‑date, create a new dev branch from the main/master branch, push it to the remote, set the upstream tracking, and verify the result in common development scenarios.
1. Ensure the local code is up‑to‑date
Run the following command to pull the latest changes from the remote repository:
git pull2. Create a local dev branch from the current main/master branch
Execute the command that both creates the branch and switches to it in one step: git checkout -b dev This command creates the branch + switches to it in a single operation.
3. Push the local dev branch to the remote repository
Use the following command to create the remote dev branch and upload your commits:
git push origin dev4. Set the upstream tracking relationship (required)
Link the local dev branch with its remote counterpart so that future git pull and git push commands work without specifying the branch name:
git branch --set-upstream-to=origin/dev devResult
After these steps you will see:
✅ A local dev branch exists.
✅ A remote dev branch has been created.
✅ The local and remote dev branches are bound, allowing simple git pull / git push operations.
Verification
Run the following command to list all branches and confirm the setup: git branch -a The output should include:
* dev
main
remotes/origin/dev
remotes/origin/mainIf these entries appear, the process succeeded.
Summary of Commands
git checkout -b dev– create the local branch. git push origin dev – push it to the remote. git branch --set-upstream-to=origin/dev dev – bind the upstream.
Typical Scenarios
Scenario 1: Project already cloned locally (most common)
Assuming you have the main/master branch locally and it matches the remote, run the three commands above directly.
Scenario 2: Project not yet cloned
First clone the repository, then create and push the dev branch in one go:
git clone https://github.com/xxx/xxx.git
cd project_folder
git checkout -b dev
git push origin devKey Takeaway
Creating a dev branch and pushing it to the remote requires that you already have the local code—i.e., you must have cloned or pulled the remote main branch first.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
liandk
Seasoned Java and mobile developer with years of experience, specializing in mini‑programs, public accounts, and full‑stack front‑end development. In the AI era, I continuously learn to broaden my knowledge and evolve. I revived a public account I started a decade ago during a dessert‑startup venture, using code as a vessel and knowledge as a companion. I share personal projects, technical articles, programming tips, and growth insights—let’s improve together and set sail.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
