0

I wish to write a python script that allows me to navigate and git pull multiple repositories. Basically the script should type the following on the command-line:

cd
cd ~/Desktop/Git_Repo
git pull Git_Repo

I am not sure if there is a python library already out there that can perform such a task.

5
  • 1
    stackoverflow.com/questions/89228/… Commented Nov 11, 2014 at 3:52
  • 1
    I don't know what other functionality you intend to add but can't you just do this as a shell one liner? for i in *; do (cd $i && git pull); done or something similar Commented Nov 11, 2014 at 3:54
  • Please let me know what works and what doesn't. +1 Commented Nov 11, 2014 at 4:45
  • Do you want Python to execute those shell commands for you, or do you just want it to print them out so you can execute them yourself (via copy & paste)? Commented Nov 11, 2014 at 5:01
  • Basically I have 5 different git repos and I want to write a python script that allows me to pull all 5 repos at once instead of me doing so manually. Commented Nov 11, 2014 at 6:52

1 Answer 1

1

Use subprocess, os, and shlex. This should work, although you might require some minor tweaking:

import subprocess
import shlex
import os

# relative dir seems to work for me, no /'s or ~'s in front though
dir = 'Desktop/Git_Repo' 

# I did get fetch (but not pull) to work
cmd = shlex.split('git pull Git_Repo') 

# you need to give it a path to find git, this lets you do that.
env = os.environ 

subprocess.Popen(cmd, cwd=dir, env=env)

Also, you'll need your login preconfigured.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.