Python Forum
[Basic] Creating a repo for your completed scripts
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Basic] Creating a repo for your completed scripts
#1
If you dont know, there are sites that you can upload your code to where people can look, upload fixes, comment on, and download your code. It makes it easier for everyone. Using weird, unknown, or massive spammy/advertisement sites to house your code turns people off from downloading it altogether. However if your code is housed in a place like github, for example, people are more apt to look/download it. It is one of the respectable website's for programmers around the world.

The two giants in the field are BitBucket and Github. The differences are negligible if you are just starting out. The major difference is Bitbucket has free private repos but makes you pay for more people to have access, while github makes you pay for private repos, but is free to have any number of people to work on your project. Between the both of them you can get free any option though. For this tutorial we are going to use Github (and that is only because i use it more as all of my code is open source). We area also going to use git to upload our code. You can think of it as....There is Github and Bitbucket to house the code (repository), and git and Mercurial to upload the code (Version Control Software). And both sites allow either. So moving from github to bitbucket isnt that hard.

Either way its a learning curve, but its worth it if you plan to upload a lot of code. You have to google questions, and how-to's. This will help teach some basics with git and github. The benefits however are awesome. You can upload your code for the ease of working with other programmers. Large amounts of people can work together. Others may make a comment on how to better your code, along with the code that they suggest. If you jump between numerous computers a lot, you can easily transfer project/files to and from any of them via your repos. Any change is saved in history, so if 6 months later you decide you want to use that one code you had, but you deleted that file, you can go back and still see the file contents and retrieve it. You can use branches to separate different "versions" of code. The list goes on and on and on....

But right now we are just going to get you started by uploading your files to github only. Something as simple as this is even helpful. For example, all of the images, sound files, music mp4's, code, and executables can be uploaded. All you have to do is provide to users the link to get there. No uploading images, or posting code to a forum like this. Just provide the link to your repo. You can clone your own repo from different computers at other locations without bringing a USB with you everywhere.

Assuming you created an account at github, here is a quick tutorial on uploading your first repo. 
1) first we need code to upload, which could be your code, or could be something as simple a text file with nothing in it. 
metulburr@ubuntu:~/repos/test$ touch test.txt
metulburr@ubuntu:~/repos/test$ ls
test.txt
metulburr@ubuntu:~/repos/test$ 
ok now we have a file called test.txt. It doesnt have anything on it, but that doesnt matter.
2) now we need to initialize git because this is a new directory that never had a .git in it before. 
metulburr@ubuntu:~/repos/test$ git init
Initialized empty Git repository in /home/metulburr/repos/test/.git/
metulburr@ubuntu:~/repos/test$
3) now we need to connect this directory with a git repo on github. Go onto the github.com, and click new repo, make a repo name (can be anything), now click create repo. It will list off a series of commands you need to make too. You will see a second url bar containing something like the address https://github.com/metulburr/test.git in it where my name of repo was "test", copy it to your clipboard. now go back to your terminal
4) in the terminal, input:
git remote add origin htps://github.com/metulburr/test.git
and replace url path with whatever yours is. Now this directory is connected to your git on the site. Note the address URL doesnt exist....is because i deleted the repo after awhile.
5) now we add the files to upload
metulburr@ubuntu:~/repos/test$ git add test.txt
metulburr@ubuntu:~/repos/test$ 
If you have other files and directories you want to add you can add everything instead via git add .
6) now we comment (which must be done)
metulburr@ubuntu:~/repos/test$ git commit -m "first commit"
[master (root-commit) 5f2c638] first commit
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 test.txt
metulburr@ubuntu:~/repos/test$ 
7) now we finally upload the file to the repo on the site:
metulburr@ubuntu:~/repos/test$ git push origin master
Depending on how you set up git or created a .netrc file with authentication in it, etc. You may also at this point have to insert your username and password that is associated with your github account. 
and there you should see the test.txt file in your new repo.

This was very cut and dry. There are a ton of things you can do, and i only named off the requirements to upload, there is more if you want to change the code you already put up, etc. etc.

For those that want to ease the method of converting to github, if your on windows, there is a GUI tool to help push/pull repos:
http://windows.github.com/

https://asciinema.org/a/8425

There is also interactive site to help you learn git as well.
https://learngitbranching.js.org/



Adding a branch
This is above and beyond simply uploading a repo tutorial. But it can make your life easier dealing with repos as well as users who use your software. Having multiple branches can leave a (set) of code for uses to use, while you make a development (set) of code updating it. Then if users want to try the dev branch, they can try new features, but might be buggy. And if they dont want to, they can use the regular master branch. This is only one example use of branches. Usually every single feature can be its own branch, etc.

create a git config file .git in the current working directory
git init
connect this repo to the online "empty" repo if starting new
git remote add origin [email protected]:USER/REPONAME.git
add everything in the current directory to the staging area. This would be your working branch before changes
git add .
make a comment (required)
git commit -m "first commit"
push staged changes
git push -u origin master
At this point what is in your directory is on the website. Lets assume this is working and in good shape. Now when you make a change and it could break things (dev)... Instead of doing the same thing as we just did and pushing the change to your master branch we you make a dev branch.


create a new branch called "dev" and switch to it
git checkout -b dev
make your changes to your code as needed
add your changed files
git add .
make a comment
git commit -m "made a change"
push staged changes to branch dev
git push -u origin dev
at which you should have 2 branches, master and dev on site. The git repo will show the master branch while you have a dev branch that is X commits further ahead but could be unstable.

At some point the dev will be stable and you can merge it into master.
switch to master branch
git branch master
merge dev into master
git merge dev
push it to the site
git push -u origin master
padma121 and like this post
Recommended Tutorials:
#2
You listed (3) twice. Great other than that!


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020