![]() The following git status command indicates that we are currently on the new “dev” branch. # git branch -aĪs you see from the above output, the * is now in front of dev, which indicates the current working branch is dev. Verify that the new branch got created as shown below. Once the empty dev branch is created, it will also switch to the dev branch and make that as our working branch.So, the above command will create a new “dev” branch. In our case, we don’t have a branch called “dev”.git checkout command will try to checkout the given branch.So, to do our development work, let us create a new local dev branch as shown below. # git branch -aĪs you see from the above output, there is no additional local or remote branch except the master branch.įor more details on git branch command, refer to this: 15 Git Branch Command Examples to Create and Manage Branches The following commands displays all available branches for this repository (both local and remote). Your branch is up-to-date with 'origin/master'. # git clone By default, the current working branch is master branch. In the following example, I’ve cloned demoproject from remote git repository to work on it locally. # Finally, delete dev branch both locally and remoteįor explanation and example output of the above steps, read the rest of the article. Git commit -m "Made the change." index.html Git clone # Create new dev branch, do your work, and commit changes locally ![]() You can either make sure your user has proper permissions or disable the protection for a few seconds until your changes are saved.For the impatient, here is the code snippet for the above steps: # Clone the git repo: The downside of this approach is that all developers who already have a local copy of the master branch will need to perform a git reset -hard.įorce pushing to the master branch might fail if you use GitLab’s “Protected Branches” feature. This solution may be appropriate in your case if you have a small number of other branches and/or other developers. Warning: this erases all commits from the master branch that are not also in the develop branch. Using the -f flag, your previous master is completely overwritten with develop, including its history. Force PushingĪ more brutal alternative is to force push the develop branch under a different name: git push -f origin develop:master The downside is that this merge might fail if your develop and master have diverged to a large degree. This method’s advantage is that you get a clean merge commit and other developers using those two branches are less likely to experience problems when merging their feature branches. The resulting master should now contain the contents of your previous develop and ignore all changes in master. You can use the following commands to merge develop into master using the ‘ours’ merge strategy: git checkout develop One way out of this dilemma is to completely replace master with the current develop. Most of those reasons suggest bad practices, but such a situation may also arise due to changes introduced into your git workflow or deployment process. You may also have a develop branch which contains code changes that are not ready for production deployment yet.įor some reason or another, you may end up in a situation where your develop has changed so much that you can no longer easily merge it into master. In many git workflows, all changes to your code should eventually end up in the master branch.
0 Comments
Leave a Reply. |