Which git hook could i use for a specific scenario - linux

I have a git remote where all users pushes to. Now i want another remote in this remote and it should automatic pushes if it receives commits.
Is that feasible, or do I have to do a git push -u origin --all with cron?

Going by the git documentation, you can add another remote url to the existing remote
git remote set-url --add --push origin <remote-url>
git remote -v should now return two urls configured for push.

Related

Push from Azure repository to cpanel private repository

I'm trying to find a way to use a pipeline to push the Azure repository to another repository on my cpanel server. At the moment I'm just transfering the files over FTP but I need a proper push to activate autodeploy on cpanel repo.
Many thanks to anyone that can help.
This process would be the same the way to commit changes to a git repository.
Initialize a git repository add the data in the staging area commit changes to local git repository then push the changes to remote git repository. The process isn't different from the normal local machine one.
git init
git add README.md
git commit -m "first commit"
git branch -M main
git remote add origin <azure repo url >
git push -u origin main

How to add Gitlab-token to sourcetree?

I try to commit a file to a gitlab repo, but I receive
git -c diff.mnemonicprefix=false -c core.quotepath=false
--no-optional-locks push -v --tags origin main:main remote: You are not allowed to push code to this project. fatal: unable to access
'https://gitlab.server.com/Edna/myproject.git/': The requested URL
returned error: 403 Pushing to
https://gitlab.server.com/Edna/myproject.git Mit Fehlern
abgeschlossen, siehe oben.
Therefore, I got a personal access token from my gitlab operator like:
abcde-aC5unFT3ELQT-VMZKSpV
How do I use this PAT? How to enable this in sourcetree git desktop tool?
Your local repository is configured to use HTTPS instead of git over ssh. The output of git remote -v should verify this. You will see something similar to:
origin https://gitlab.server.com/Edna/myproject.git (fetch)
origin https://gitlab.server.com/Edna/myproject.git (push)
Follow the instructions to create and add your SSH key to your GitLab account.
Then, use a SSH remote repository for origin.
$ git remote rename origin https-origin
$ git remote add origin git#gitlab.server.com:Edna/myproject.git
Then, try your git command.

Gitlab pushing first project failed due to could not read from remote repository

I was new to Gitlab was trying to push my project from local machine to Gitlab.
Have done the SSH key and followed the instructions at Gitlab. Done the Git global setup. Was trying to add an existing folder , so i followed the instructions listed
cd existing_folder
git init
git remote add origin https://gitlab.com/sss/testnode.git
git add .
git commit -m "Initial commit"
git push -u origin master
but failed at the last step at the git push. The error message was
Tried adding the remote origin, but it was told it already exists. So not sure where it went wrong. Please help, much appreciated :)
Have done the SSH key
The problem is that you have defined your origin as HTTPS, not SSH.
Try:
git remote set-url origin git#gitlab.com:sss/testnode.git
That will override origin URL.
Independently, make sure your SSH key does work and allows GitLab to authenticate you as your GitLab account with:
ssh -T git#gitlab.com
Check out your credentials, if they are invalid, it wont give u to upload changes.
For Windows check this: https://www.digitalcitizen.life/credential-manager-where-windows-stores-passwords-other-login-details
For Linux check this: https://askubuntu.com/questions/30907/password-management-applications (if you do not know how to change credentials via terminal)

Git pull via SSH

I try set up jenkins for automatically execute git pull from bitbucket. I created an SSH on repository and executed ssh -T git#bitbucket.org and got response:
authenticated via a deploy key. You can use git or hg to connect to Bitbucket. Shell access is disabled.This deploy key has read access to the following repositories:
If I try execute ssh git pull the console does infinite loading.. Why?
Did you clone repository? You should be able to login to Bitbucket web interface and in you profile add your public SSH key.
Then you can clone repository. From Bitbucket webinterface --> repo --> click on clone. This will pop up window with ssh command to clone repository.
Once you repo is cloned, you should be able to use
git pull
...edit,add,commit
git push
There is no need to manually open SSH connection - git will do it itself. You just need to tell git to pull a specify from which repository. Git will parse the URL, and invoke SSH if needed.
And this is the best practice to disable shell access to git hosts. See e.g. https://git-scm.com/book/en/v2/Git-on-the-Server-Setting-Up-the-Server

How does Git know which repository to push to?

I'm a complete noob when it comes to version control, but I recently started using GitHub to host some of my projects. I blindly use the command git push origin master to push changes to either of the two repositories. I don't understand how Git knows which repository to push to. I use the same command to push to each. Does the directory I'm in have anything to do with it?
Thanks for clearing this up for me.
A word of advice, "blindly use"ing anything is a bad idea.
git has a system of remotes which allows to specify URLs and transports to repositories other than the one where you're working. git push origin master pushes the current branch to the remote called origin as the branch master. You have a remote called origin. This is created by default when you clone a repository from a URL.
git remote add origin http://abc.com/def/ghi.git tells git the url that remote 'origin' points to.
When you use git push origin master, you aren't pushing to two repositories - you are pushing to the master branch in your repository who's name (alias) is origin.
Think of it like this:
I'm pushing my stuff to origin which is my repository address. What am I pushing there? My master branch.
If you are new and set git up yourself through git init, you probably aren't pushing to two repositories. Run this command to see what your remotes are:
git remote -v
This will return something like (assuming you have a git hosting service like github):
blahblah git#github.com:yourGithubName/fileName.git (fetch)
blahblah git#github.com:yourGithubName/fileName.git (push)
git#github.com:yourGithubName/fileName.git is your repository address. Some addresses are prefixed by https:// .
Git repositories contain a .git directory that contains metadata about the repository. That's what Git uses to determine where to push your changes.

Resources