This Go program automates the process of pulling all local branches in a Git repository if their corresponding remote branches exist. It traverses a specified root directory, identifies Git repositories by the presence of a .gitignore file, and updates the branches in each repository.
- Recursively traverse directories to find Git repositories.
- Pull updates for all local branches that have corresponding remote branches.
- Go 1.16 or higher
- Git
- Clone the repository:
git clone <repository-url>
- Navigate into the project directory:
cd git-branch-puller - Build the Go application:
go build -o git-branch-puller
- Run the built executable:
./git-branch-puller
- Enter the root directory when prompted:
Bitte geben Sie das Root-Verzeichnis ein: /path/to/root
- The program will recursively traverse the specified root directory, find Git repositories, and pull updates for all local branches that have corresponding remote branches.
$ ./git-branch-puller
Bitte geben Sie das Root-Verzeichnis ein: /home/user/projects
Git-ähnliches Verzeichnis gefunden: /home/user/projects/repo1
Branch main in /home/user/projects/repo1 erfolgreich gepullt.
Branch dev in /home/user/projects/repo1 erfolgreich gepullt.
Git-ähnliches Verzeichnis gefunden: /home/user/projects/repo2
Branch main in /home/user/projects/repo2 erfolgreich gepullt.
Remote-Branch feature does not exist, skipping pull in /home/user/projects/repo2.- Root Directory Input: The program prompts the user to input a root directory.
- Directory Traversal: It recursively traverses the given directory using
filepath.Walk. - Git Repository Detection: For each directory, it checks for the presence of a
.gitignorefile to identify Git repositories. - Branch Pulling:
- Retrieves all local branches using
git branch. - Checks if the corresponding remote branch exists using
git ls-remote. - For each local branch with a corresponding remote branch:
- Checks out the branch.
- Pulls updates from the remote branch.
- Retrieves all local branches using
- The program outputs error messages if any issues occur during directory traversal, branch checking, or branch pulling.
- It skips directories that do not contain Git repositories and continues with the next ones.
Contributions are welcome! Please follow these steps to contribute:
- Fork the repository.
- Create a new branch for your feature or bugfix:
git checkout -b feature-name
- Commit your changes:
git commit -m "Add new feature" - Push to the branch:
git push origin feature-name
- Create a pull request.
This project is licensed under the MIT License. See the LICENSE file for details.
This project was inspired by the need to efficiently manage multiple Git repositories and keep local branches updated.