Home > Enterprise >  Best way to push the project folder into GitHub
Best way to push the project folder into GitHub

Time:10-12

I have a python project and i am trying to write a script to push the project folder into git

What are the steps that should be taken

I have tried https://www.freecodecamp.org/news/automate-project-github-setup-mac/ but cant seem to fix it

CodePudding user response:

Firstly, you need to create a repo on the Github UI. After creating the repo, Github will give you a URL to that repo. Assuming you have SSH keys setup, you'll then be able to use that URL to push your commits like so:

On a project directory:

git init  # initialize a repo; create a .git folder with git internal data
git add file1.py file2.sh file3.js README.md  # choose which files you'd like to upload
git commit -m "Add project files"  # create a commit
git remote add origin "github repo url"
git push  # upload commit to Github

Automating this "first push" for several projects is relatively easy. Just be careful with what files you're going to git add. Git is not designed to version binaries like images, pdfs, etc.

CodePudding user response:

I use this code. Assuming you have SSH keys setup.

import os
from datetime import datetime

current_time = datetime.now().strftime("%H:%M:%S")


os.system("git init")
os.system("git remote rm origin")
os.system("git remote add origin https://github.com/user/repository")
os.system('git config --global user.email "[email protected]"')
os.system('git config --global user.name "username"')
os.system("git rm -r --cached .")
os.system("git add .")
git_commit_with_time = f'git commit -m "update:{current_time}"'
os.system(git_commit_with_time)
os.system("git push -f --set-upstream origin master")

You can also customize it according to you.

You can use something else instead of the current_time in the commit.

I have been using this for many months and I found it the best way. Because since I have automated the task, I have not had any problem till date.

  • Related