Skip to content

Instantly share code, notes, and snippets.

@matthewr6
Created July 5, 2016 01:55
Show Gist options
  • Save matthewr6/987542bab715f619a88f3b0b23738836 to your computer and use it in GitHub Desktop.
Save matthewr6/987542bab715f619a88f3b0b23738836 to your computer and use it in GitHub Desktop.
automatically pull from master for all directories at the same level
package main
import (
"os"
"fmt"
"os/exec"
"io/ioutil"
)
func main() {
dirs, _ := ioutil.ReadDir("./")
for _, dir := range dirs {
if dir.IsDir() {
dirName := fmt.Sprintf("./%v", dir.Name())
_, err := os.Stat(fmt.Sprintf("%v/.git", dirName))
if err == nil {
os.Chdir(dirName)
_, err := exec.Command("git", "pull", "origin", "master").Output()
if err == nil {
fmt.Printf("Successfully pulled master into %v\n", dir.Name())
} else {
fmt.Println(err)
}
os.Chdir("..")
}
}
}
}
@matthewr6
Copy link
Author

matthewr6 commented Jul 5, 2016

my-directory
+-- autopull.exe
+-- git-repo-1
|   +- .git
|   +- files
+-- git-repo-2
|   +- .git
|   +- files
+-- git-repo-N
|   +- .git
|   +- files

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment