Way to import code from specific branch of repo?

I noticed that Glitch only seems to import the master branch of my github project, with no option to import the specific branch I am working on and need feedback on. Is there way to import just the code for a specific branch? Sounds like others have asked about this issue before, but I see that was raised last year.

3 Likes

Hi @dennisgit42,

each project has its own git repository (if you just created your project, give it around 10 minutes for it to be created). So if you access the Terminal (Project menu -> Advanced Options -> Terminal) you can add the github project as a remote and then pull the branch you prefer :slight_smile: If you need further guidance let me know!

Hello @etamponi How can I do that you’re mentioning? pulling the branch I prefer :smile:

You would have to use git commands in the console to do that. You can’t do it right now with the GH import function.

How can I do that? I’m doing it this way…

Right now, GH import just pulls the code from GH, not the history of the repository, so you don’t have any branches locally, and the remote hasn’t been set up to point to GH. The best way to do this right now would be to delete your app directory, and clone from GH into that directory.

cd /
rm -rf /app
git clone https:/github.com/<some-project> app
cd app
git checkout <some branch>

This will delete whatever is in your project, so make sure there’s nothing you care about in there.

1 Like

It just occurred to me that you can’t completely remove the app directory. Instead, do this:

rm -rf /app/*
rm -rf /app/.*
1 Like

I’m trying to clone a private repository and if I do that like you mention I get this

Maybe try git clone https://[insert username]:[insert password]@github.com/[insert organisation name]/[insert repo name].git

thank you @Gareth , I did a bit different but same; idea: instead of https://username:password@github.com/username/repository.git just https://github.com/username/repository.git and, the console asked for the credentials.

So now it works! thanks! I did like this:

rm -rf /app/*
git clone https::github.com/username/repository.git app
cd app
git checkout the-branch
2 Likes

Thanks for these instructions – could someone offer advice for this process, but setting a particular sub-directory from the repo branch as the app? With the import interface, we can use : to grab a sub path… how would I do this after successfully cloning via console?

edit: nevermind, just realized I could cd into the dir and move its contents back to the root level:

cd to/the/dir
mv * ../../
1 Like

You could also try

git checkout

to switch branches, that you are working on

Thank you! Kept trying to import a project from github, set the remote repo, nothing worked right. Your steps (followed by a final ‘refresh’ in the console) were perfect. Thanks a lot!

Thank you! I didn’t know about refresh and was wondering why the editor wouldn’t update.

refresh