Skip to content

Username and password authentication #1694

Closed
@krupis

Description

@krupis

Hello. I recently came across this library for git on Python. I am working on a project where client needs to have a script which he can run to fetch/pull all the changes from my git repository.

The most important thing is that the computer will not have any SSH keys associated with gitlab therefore it will need to use username and password for authentication. I havent managed to find a way how to do this using GitPython.

I can use the following script to commit and push to the repository:

import git

full_local_path = "C:/Users/test/Desktop/WORK/Test/test_main/testfw"
branch_name = "test_branch"
repo = git.Repo(full_local_path)
origin = repo.remote(name="origin")

# COMMIT & PUSH
repo.index.commit("Some commit message123")
origin = repo.remote(name="origin")
origin.push()

print("Script complete")

The above script will work without any issues on the machine that has SSH keys for authentication.

However, my other Raspberry PI device will not have SHH keys and I want to be able to authenticate using username and password.
Currently, I manually have to fetch and pull all the changes as following:

My_raspberry@raspberrypi:~/DEV/testfw/fw $ git push
Username for 'https://xxx-gitlab.xxxxxx.lt': [email protected]
Password for 'https://[email protected]@xxx-gitlab.xxxxxx.lt': 
Enumerating objects: 8, done.
Counting objects: 100% (8/8), done.
Delta compression using up to 4 threads
Compressing objects: 100% (8/8), done.
Writing objects: 100% (8/8), 974 bytes | 487.00 KiB/s, done.
Total 8 (delta 7), reused 0 (delta 0), pack-reused 0
remote: 
remote: To create a merge request for test_branch, visit:
remote:   https://xxx-gitlab.xxxxxx.lt/test/testfw/-/merge_requests/new?merge_request%5Bsource_branch%5D=test_branch
remote: 
To https://xxx-gitlab.xxxxxx.lt/test/testfw.git
   761a21c..c10b27e  test_branch -> test_branch 

and it will work fine without any issues. I was hoping to automate this process using GitPython.

Any help is appreciated

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions