Search code examples
javagitlabgitlab-api

gitlab API gitlab4j Java change default branche


I'm using gitlab4jto change project default branch from master to dev with Java, I have authenticated changed the default branch but changes not saved

GitLabApi gitLabApi = new GitLabApi("***", "mytoken");
List<Project> projects = gitLabApi.getProjectApi().getProjects();

for (Project project : projects) {
    if(project.getId()==633) {
        project.setDefaultBranch("dev");            
    }
}

Solution

  • i Hvae resolved this problem by adding :

    gitLabApi.getProjectApi().updateProject(project);

    so the new code is :

    for (Project project : projects) {

            if(project.getId()==633) {
                project.setDefaultBranch("dev");
                gitLabApi.getProjectApi().updateProject(project);
    
            }
    
        }