已在SourceTree克隆GitHub仓库,如何关联Android Studio实现修改同步?
Got it, let's walk through how to link SourceTree with Android Studio so your changes sync seamlessly. Here's a step-by-step breakdown that's worked for me and other devs:
Step 1: Ensure Android Studio uses the correct Git executable
First, we need to make sure Android Studio is using the same Git instance as SourceTree (this avoids any weird sync conflicts):
- Open your cloned project in Android Studio
- Go to
File > Settings > Version Control > Git(Windows/Linux) orAndroid Studio > Settings > Version Control > Git(Mac) - In the
Path to Git executablefield, use the same Git path that SourceTree uses. You can find this in SourceTree: go toPreferences > Git(Mac) orTools > Options > Git(Windows), copy the path, and paste it into Android Studio - Click
Testto confirm Android Studio can connect to Git successfully
Step 2: Link Android Studio to your existing Git repository
If Android Studio hasn't automatically recognized your cloned repo:
- Go to
File > Settings > Version Control - Click the
+button, selectGit, then navigate to your project's root folder (the same one you cloned with SourceTree) and clickOK - Now Android Studio will track all file changes in your repo automatically
Step 3: Add SourceTree as an external tool in Android Studio (optional but convenient)
To open SourceTree directly from Android Studio for repo management:
- Go to
File > Settings > Tools > External Tools - Click the
+button to create a new tool:- Name: SourceTree
- Program: Paste the path to your SourceTree executable (e.g.,
C:\Users\<YourUsername>\AppData\Local\SourceTree\SourceTree.exeon Windows,/Applications/SourceTree.app/Contents/MacOS/SourceTreeon Mac) - Arguments: (Optional) Add
open "$ProjectFileDir$"to launch SourceTree directly on your project repo
- Save the tool. Now you can access it via
Tools > External Tools > SourceTreeanytime
Step 4: Sync changes between Android Studio and SourceTree
Once everything is set up, the workflow is straightforward:
- Make code changes in Android Studio: modified files will show up as blue, new untracked files as red
- Commit changes locally in Android Studio via
VCS > Commit(add a meaningful commit message!) - Open SourceTree: you'll immediately see your new local commit in the repo's history
- Use SourceTree for remote operations:
Pushto GitHub,Pullupdates, merge branches, or resolve conflicts - If you make changes in SourceTree (like pulling remote updates), go back to Android Studio and run
VCS > Update Projectto sync the code
Quick Tips
- Always double-check that both tools are pointing to the exact same local repo folder—this is the most common sync issue
- If Android Studio doesn't pick up changes, run
VCS > Refresh File Statusto force a status update - Before pushing, use Android Studio's
Code > Inspect Codeto catch any issues early
内容的提问来源于stack exchange,提问作者John Alex jefferson
相关产品推荐
相关产品推荐

