Dummy questions about setting up git on amazon cloud ec2

前端 未结 3 967
北恋
北恋 2021-02-03 11:59

first of all, apologize for dummy questions that I might throw here. It would be nice if you could point the directions where should I go from here.

I\'m totally new to

相关标签:
3条回答
  • 2021-02-03 12:31

    look here for more information on setting up git on amazon ec2

    to allow developers to use you git, you just need to give them the git server url.

    Direct quote from the site i'm linking to.

    "First and foremost, you need to add your EC2 identity to the ssh authentication agent. This prevents problems with git later, namely getting the error “Permission denied (publickey).” when trying to do a git push to the EC2 repository.

    ssh-add path/to/privateEC2key.pem
    

    Now you can go ahead and create the git repository on the EC2 instance.

    ssh username@hostname.com 
    mkdir the_project.git 
    cd the_project.git 
    git init --bare
    

    So not much going on here, all we do is create an empty repository and then leave. Now, on the local machine, you do something like the following:

    cd the_project 
    git init
    git add . 
    git commit -m "Initial git commit message" 
    git remote add origin username@hostname.com:the_project.git 
    git config --global remote.origin.receivepack "git receive-pack" 
    git push origin master
    

    The ‘git config’ command is a fix that I found necessary to be able to push to the EC2 repository."

    0 讨论(0)
  • 2021-02-03 12:45

    The mentioned link by Alex gives a good starting point to setup git on ec2. But I followed a little different approach as mentioned here. link. Direct Quotes from the page:

    "Connecting with SSH without a PEM key" : So either you add the ec2 private key and add it as a entity in your ssh authentication agent or create a new ssh key for your user and use that. Steps to be followed are:

    Create SSH Key

    First up you will need to navigate to your .ssh folder on your local machine :

    cd
    cd .ssh
    

    if this folder doesn’t exist use mkdir to make it.

    Once in your ssh folder on your local machine which should be in /Users/yourusername/.ssh generate your key by executing the following.

    ssh-keygen -t rsa -b 1024
    

    When prompted enter the file name to save the key enter id_rsa_aws, when prompted to enter a password leave blank.

    In your .ssh directory execute the following command and copy the output to paste later.

    cat id_rsa_aws.pub
    

    Now connect to you AWS instance using you PEM key

    ssh -i path/to/yourkeyname.pem ubuntu@xx.xxx.xxx.xxx
    

    Once in

    echo 'the key you copied from id_rsa_aws.pub' >> .ssh/authorized_keys
    chmod 640 .ssh/authorized_keys
    chmod 750 .ssh
    

    Now you go to your machine and type

    cd desired directory
    git clone ubuntu@xx.xxx.xxx.xxx:<path_to_your_just_created_git_server>
    

    If you did all the above mentioned steps correct, the only warning you might get is

    warning: You appear to have cloned an empty repository.
    

    That's ok. Now you can copy all your code into the clone directory, and follow the following steps:

    git add . 
    git commit -m "Initial commit"
    git push origin master // If working on master branch
    
    0 讨论(0)
  • i created a GitHub gist with all the details hope it helps https://gist.github.com/eslam-mahmoud/35777e4382599438023abefc9786a382

    //add your EC2 .pem file to ssh kys
    ssh-add ~/aws/mypemfile.pem 
    
    //create bare repo on AWS EC2 webserver and deploy on demand
    mkdir ~/git/the_project 
    cd ~/git/the_project
    git init --bare
    
    //create local repo and track remote one
    cd ~/git/the_project 
    git init
    git add . 
    git commit -m "Initial git commit message" 
    git remote add aws ubuntu@1.1.1.1:~/git/the_project 
    git config --global remote.origin.receivepack "git receive-pack" 
    git push aws master
    //create tag
    git tag -a v0.1 -m "my version 0.1"
    //push tags
    git push aws --tags
    
    //Or you have one so you push your updates 
    git remote add aws ubuntu@1.1.1.1:~/git/the_project 
    git config --global remote.origin.receivepack "git receive-pack" 
    git push aws master
    //create tag
    git tag -a v0.1 -m "my version 0.1"
    //push tags
    git push aws --tags
    
    //on server create another local repo that track the bare one to deploy
    git clone ~/git/the_project
    cd ./the_project
    //checkout tag
    git checkout v0.1
    //install clear cache ...
    npm install
    
    0 讨论(0)
提交回复
热议问题