Gists Vrs Repos for sharing Pythonista code
I was reading about Gists, and the docs say that they are functionally equivalent to repos, in regards to cloning, forking etc...
@ccc, I noticed you had a post before about Gists being unmanaged. Have they changed since you wrote that? Or are Gists inferior to repos. From what I read, a gist is a repo.
I understand this is not Pythonista specific, but just trying to work out the best way to go. As Pythonista has some support for Gists, it would make sense to use them if they are functionally equivalent.
As far as I know you can do all the important things with the
gitcommands in stash. The most important ones you need to know are:
git clone https://github.com/username/reponame.gitto download a repo's contents into the current folder, so do it in a new empty folder or have fun cleaning up the mess afterwards.
git pullto update an existing repo to the version available on GitHub. (You don't need to specify the URL here, because it's already stored in the
git statusto see which files have changed locally, and which modifications will happen in the next commit (see below).
git rmto add or remove a file from the next commit.
git resetto undo any changes since the last commit.
git committo save the changes in the repo as a new commit. When you run the command, you'll be asked to enter a commit message, where you should write a short one-line description of the changes you made. (On a real computer you can write a more detailed description in multiple lines, no idea if that's possible in stash.) The first time you commit to a repo (after you've cloned it) you're also asked to enter your username and e-mail address, which should be the same that you use on GitHub.
git pushto publish any local commits to GitHub. The first time you do this you're asked to enter your GitHub username and password. Obviously this step only works for repos that you have write access to.
Also see this very short guide to Git.
Did you write the guide with a desktop as part of the work process because it sort of has to be?
I used the GitHub Desktop app only because I never got a complete answer to https://forum.omz-software.com/topic/2382/git-or-gist-workflow-for-pythonista/2
If someone can create an alternative version of https://github.com/cclauss/GitHub-web-plus-app-workflow that uses Working Copy app instead of GitHub Desktop, that would be great.
@dgelessus With my method, I found that I had to fork instead of clone but perhaps that is rendered unnecessary by your
EDIT: 'When you are cloning a GitHub repo on your local workstation, you cannot contribute back to the upstream repo unless you are explicitly declared as "contributor".' From: http://stackoverflow.com/questions/6286571/are-git-forks-actually-git-clones
@dgelessus and @ccc , wouldn't you say the smartest thing would be for the top notch programmers come together and create a simple to use app using the the Pythonista ui libs. Something as close to fool proof as you can get.
I understand cmd line interfaces are very powerful. But this subject is at the core. I am sure I am not the only guy that can not make heads or tails of this, even when it's spoon fed to me.
I am not trying to be difficult, but Github with a user interface is difficult anyway, let alone a series of cmd line operations. For me, I cross my fingers and hopes it works out.
But again I will be blunt with you guys. I think you don't get how difficult it is, just because you know it like the back of your hand. And if you struggle occasionally, imagine how the rest of us fair? Not so good!
Really, if I had the skills. The backup/restore issue would be the first thing I would tackle, this would be the second. But not by myself, need to get a consensus that this is the tool for backups, and this is the tool for Github. Others not supported. Some lines need to be drawn in the sand sometimes. I think this is one of those times.
Well, that's my idea anyway. I know how structured you guys are in your business life, I don't see this should be different.
@Phuket2 I might eventually decide to work on some kind of code-sharing app built just for Pythonista, as I think it'd be worth doing.
It'd be a script that automated uploading / downloading code to and from a database. The database would probably be a GitHub repo, but the script would provide a foolproof front-end.
It'd have to be a bit more complicated than that, though, because I wouldn't want to give people write access to the repo just by reading through the script's code. The way I'd do this would probably be to have a web service on my server that took requests and posted content on GitHub. This way, I wouldn't have to include the password to the GitHub repo in the script that I had people download. The web service would only provide methods for uploading new scripts and for downloading scripts, not for editing, that way nobody would be able to undo others' work besides myself.
I'm not actually sure how to store a password inside the web app such that it can't be accessed publicly. I've asked on security.stackexchange.com to see if anyone knows.
Here is a howto clone your own repo, change a file and push it back with stash.
[~/Documents]$ mkdir Github
[~/Documents]$ cd Github
[Github]$ mkdir ui-tutorial
[Github]$ cd ui-tutorial
[ui-tutorial]$ git clone https://github.com/humberry/ui-tutorial.git
.git (374.0B) 2016-02-16 21:27:36
MiniPhotoView.py (3.4K) 2016-02-16 21:28:55
[ui-tutorial]$ edit MiniPhotoView.py
[ui-tutorial]$ git status
UNSTAGED LOCAL MODS
[ui-tutorial]$ git commit
Commit Message: remove touch and layout method
Author Name: myusername
Save this setting? [y/n]y
Save this setting? [y/n]y
[ui-tutorial]$ git push
Attempting to push to: https://github.com/humberry/ui-tutorial.git, branch: refs/heads/master
Enter username: myusername
Enter password: mysecretpassword
Push to https://myusername:firstname.lastname@example.org/humberry/ui-tutorial.git successful.
@ccc The commands I listed are for working with a repo that you own or have write access for. I'm not sure if GitHub forking is possible from the command line, there seems to be a lot of GitHub-specific stuff involved with the process. (Honestly I don't know how one would fork a repo independent of GitHub, or if that really just involves making a copy of the repo.)
Guys.... Dealing with a repo that you own is child's play.
GitHub's examples explain the entire workflow of dealing with your own repo in an easy to understand way. You have full read/write permissions so you can just Push changes directly into the repo without even needing to resort to Pull Requests.
The complexities for me come when I want to send a Pull Request into a repo that I do not own and I am not a "contributor" to. That is why the bold text in my post above is: create Pull Requests into GitHub repositories that I do not own.
I would still really like to see someone replicate my approach above using Working Copy app in place of GitHub Desktop.
@ccc GitHub specific functions can be accessed through GitHub API v3, including fork, create pull request etc. It should be possible to write a command line tool for them. But it is so convenient already to just do them via the webpages. It seems to me that the API is really for people who develope apps for GitHub, eg working copy. If you don't pay for the API, it is limited to about 60 calls per hour.
@ccc I do the initial "fork" of the repo using the website. Then I can create branches off my fork's
masterbranch and commit to them using the command line. That should also be possible in stash. Once I'm done I send the PR through the website again.
If my fork's
masterbranch gets outdated, I do
git merge upstream/master(replace
upstreamwith the original repo owner name, or add it as a remote by hand) which should always result in a fast-forward because I never do any changes to my
@ywangd Github has the
hubcommand-line tool for these things https://hub.github.com. It provides all git functions, as well as some that are specific to GitHub. They recommend aliasing
hubto make it the default command-line interface for Git.
@Webmaster4o Thanks I wasn't aware of this tool. But it does not help in our situation as it cannot run inside Pythonista or even iOS. It is written in Go.
@ywangd Right. I was just pointing it out ;)
Guys, I hope I didn't come off as complaining. I have a very high regard for all you guys and how much you are will to share and do. I was just emotional and frustrated. But the good news is you only get emotional about things you care about. It looks @ccc post got the topic started again though was is great. I think one thing that frustrates me, is that I can only talk about it. I can't really do anything that I am aware to contribute.
Oh, well. As I say just hope I didn't offend anyone. Was the furthest thing from my mind.
For what it is worth, PyGithub seems to work well. I may wrap a simple stash commandline around this. pygithub doesn't seem to support creation of files, but that is what stash git is for. There may be other forks with more complete support (enix223/master).
Anyway, the short and sweet:
Create new repo:
from github import Github g = Github(user,pass) #or, g=Github(token) where token is personal Oauth token u= g.get_user() u.create_repo('new_repo')
or, to Fork a repo
other_repo = g.get_repo('cclauss/GitHub-web-plus-app-workflow') mine=u.fork_repo(other_repo)
Create a pull request (after using stash to push to your own github)
# call create_pull on the repo you want to pull INTO. base = name of branch in that repo. head = name of YOUR repo, as user:branch other_repo.create_pull(title='A web-free example, using only python', body='here is a simple example using pygithub to fork a repo, then create a pull request', base='master', head='jsbain:master')