乐闻世界logo
搜索文章和话题

How to push new branch without history with git

1个答案

1

Pushing a new branch with no history to a remote repository is a common requirement, especially when starting a new feature or module. Here are the steps to push a new branch to the remote repository:

Step 1: Create a Local Branch

First, create a new branch in the local repository. Assume we want to create a branch named feature-new; we can use the following command:

bash
git checkout -b feature-new

This command creates a new branch feature-new and automatically switches to it.

Step 2: Add Some Changes (Optional)

Make some changes on the new branch. For example, add new files or modify existing files. After completion, stage these changes and commit them. For instance:

bash
git add . git commit -m "Initial commit in feature-new"

Here, the git add . command stages all changes, and git commit -m "Initial commit in feature-new" creates a new commit.

Step 3: Push to Remote Repository

Now, push this new local branch to the remote repository using the following command:

bash
git push -u origin feature-new

Here, the git push command pushes the local branch feature-new to the remote repository. The -u option tracks the local branch with the remote branch, so in future operations, you only need to run git push or git pull to keep the branch synchronized between remote and local.

Example

Suppose you are developing a new feature and need to add a new module to the project. You can follow the above steps to create a new branch, develop it, and then push it to the remote repository. This way, other team members can see this new branch and pull it as needed for collaboration and contributions.

By doing this, we ensure more efficient organization and management of code, and maintain clarity and order in the development process.

2024年6月29日 12:07 回复

你的答案