← Back to the Blog

Using curl and github API

Git CLI suite is awesome, still we have to login into Github GUI to do something like creating or deleting a new repository,

Full link to github API reference:

 

using curl to create a new repo from command line:

Let's assume, we've got a Personal Access Token generated on a github profile page as following: Github Settings > Applications -> Personal Access tokens -> add a new token
and set $NEWREPO as a desired new Repository name.

git config --global --add github.user ${GITUSERNAME}
git config --global --add github.token ${GITTOKEN}
export NEWREPO=testrepo


curl -u "$(git config github.user):$(git config github.token)" \
https://api.github.com/user/repos -d '{"name":"'$NEWREPO'"}'

Success! Now we've got response in JSON format within a new repository description


 

applying pull request using curl and github API:

Traditional way to apply github pull request, first saving it into a local repository:

$ git checkout master
$ git remote add $name git://github.com/$GITUSERNAME/$PROJECT.git
$ git fetch $REPONAME
$ git merge $name/error-page
$ git push origin master

If we have a corresponding pull request number (definred as $REQUEST), we can apply (or fetch and pre-review) patch faster from command line, using curl and github API:

git checkout master
$ curl https://github.com/$GITUSERNAME/$PROJECT/pull/$REQUEST.patch | git am
$ git push origin master

Be the first to reply