0

how to automate the “pull-and-push” process? (git) Username and Password authentication

So i have written a bash file as below, but after the process the other git server prompts for username and password as authentication, how do i write that script. Also if my current script is ok? manually everything works fine

#!/bin/bash

cd /home/****/Desktop/test
git clone --bare https://gitlab.com/***/pullpush.git
cd /pullpush.git
git push --mirror https://ip_address/***/test-project.git
jeb
  • 78,592
  • 17
  • 171
  • 225
Anshuman Bardhan
  • 1,986
  • 2
  • 8
  • 10
  • If you need authentication, why you don't switch to private/public key via ssh? – jeb Dec 04 '19 at 11:19
  • yep worked! ill be posting soon how it did, but i am stuck in the third line, while executing bash file after all the repo are available then i need to enter the directory pullpush.git file from where i need to execute the last command.. So i m unable to do that, can u help with that? – Anshuman Bardhan Dec 04 '19 at 11:53
  • https://stackoverflow.com/search?q=%5Bgit%5D+cache+password – phd Dec 04 '19 at 12:03

1 Answers1

1

You should be using ssh instead of https to work with git. You can find the documentation here :

https://help.github.com/en/enterprise/2.15/user/articles/adding-a-new-ssh-key-to-your-github-account

This will not prompt you for any password.

Assuming that for some reason you cant use ssh, and you have no other option than using https, then you can create a personal token and you wont be password prompted neither. Docs here :

https://help.github.com/en/enterprise/2.17/user/authenticating-to-github/creating-a-personal-access-token-for-the-command-line

Matias Barrios
  • 4,674
  • 3
  • 22
  • 49