詳細検索

It's OPS, but I tried using git ~ Part 1

Avatar
by komi

It's OPS, but I tried using git ~ Part 1
Translated from 日本語 • View original

Hello. This is Komiya. It's OPS, but I tried using Git ~ Part 1, so don't forget to take notes because I'm a beginner in GitHub, GitLab, and Git. This time, I'll just push it stutteringly. If you cut the branch, you will be full if you write it from the first time. Maybe up to number two. Part 2 is about branch, tag, and confrict.

Background and Advantages and Disadvantages

・Background Due to the recent continuous integration, there was a demand for server construction in chef, and I had the opportunity to hit the stray bullet, so I needed to version control the repository, so I decided to use git. At first, I had it stored on the company's enterprise version of GitHub, but due to the demand for communication via VPN, I decided to introduce gitlab. ・Advantages of git You don't have to follow history. Visualization. The difference in the file is easy to see, so it is easy to check in the browser ・Disadvantages of git Colleagues don't start using it (if you don't need it, you tend to be busy and go through) Well, I understand how you feel. I also felt that the trigger was semi-forced.

Differences between github and gitlab I don't think there is much change in terms of git commands, but it would be nice to see if the system can be open (enterprise can be closed) or closed, and in the case of gilab, the capacity limit can also be set in detail depending on the environment such as disk space.  You will have the freedom to avoid using a VPN. It is the difference between using a shared web service or using a self-built one.  It seems that the time and effort of introducing gilab has recently been reduced by the fact that there are recipes that can be easily entered by chef.

For GitHub, do something about two-factor authentication

I won't go into details, but first register on github and manage the company's github two-factor authentication → follow the manual prepared by the company.   In short, it is like two-factor authentication in gmail, and it is a mechanism to authenticate when you receive an SMS notification on your phone.

Create an SSH key on the host you want to connect to and register the created public key in your GitHub user profile.

Initialize git on the host you want to push

First, register the user information of the person who typed the git command.

git config --global user.email "komiyay@xxxxx"`
git config --global user.name "Yxxx Komiya"

If you do not specify the memory limit or the number of threads in the configuration file, you will get an OutOfMemory error.

$ vi ~/.gitconfig
[user]
        email = komiyay@xxxxx
        name = Yxxx Komiya
[core]
        packedGitWindowSize = 128m
        packedGitLimit = 128m
[pack]
        windowMemory = 128m
        threads = 2
        deltaCacheSize = 128m
        packSizeLimit = 128m

*I set this setting to about m1.small. T1.micro gave me a memory error.

Memory error message:

fatal: Out of memory, malloc failed9.59 MiB | 4.16 MiB/s
error: pack-objects died with strange error
Register a git repository and push with add and commit

I will execute the command as described in the description of the github repository that you created (*). *I have not been given permission to create a repository (because it is a private repository of the company) After moving to the repository of the chef you want to register, do the following.

touch README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin git@github.com:Isaoxxxx/xxx-chefrepo.git
git push -u origin master

git remote add and you will see something like this:

$ git remote -v
origin  git@github.com:Isaoxxxx/xxx-chefrepo.git (fetch)
origin  git@github.com:Isaoxxxx/xxx-chefrepo.git (push)
git push failed

The reason is that I accidentally committed a large file of 100MB or more. (For GitHub.) gitlab has no particular limit) If it's not more than 100MB, it seems like it's not good to archive middleware. remote_file resource or download it after git clone.

$ git push -u origin master
Warning: Permanently added the RSA host key for IP address '192.30.252.128' to the list of known hosts.
Counting objects: 557, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (451/451), done.
Writing objects: 100% (557/557), 587.22 MiB | 11.26 MiB/s, done.
Total 557 (delta 126), reused 0 (delta 0)
remote: error: GH001: Large files detected.
remote: error: Trace: 5f467e50268ce9aec1f53188e8e52882
remote: error: See http://git.io/iEPt8g for more information.
remote: error: File site-cookbooks/java/files/default/usr/local/src/jdk-7u45-linux-x64.rpm is 116.91 MB; this exceeds GitHub's file size limit of 100 MB
remote: error: File site-cookbooks/mysqld/files/default/usr/local/src/MySQL-5.6.15-1.linux_glibc2.5.x86_64.rpm-bundle.tar is 294.62 MB; this exceeds GitHub's file size limit of 100 MB
remote: error: File site-cookbooks/play/files/default/usr/local/src/play-2.2.1.zip is 104.82 MB; this exceeds GitHub's file size limit of 100 MB
To git@github.com:Isaoxxxx/xxx-chefrepo.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'git@github.com:Isaoxxxx/xxx-chefrepo.git'

URL in the error message ↓ English. Working with large files · GitHub Help I couldn't just 'git rm' and 'git commit'. As shown in the URL below, special operations were required. When you commit a file over 100MB and the push is rejected by github

$ git filter-branch --force --index-filter 
  'git rm --cached --ignore-unmatch site-cookbooks/play/files/default/usr/local/src/play-2.2.1.zip' 
  --prune-empty --tag-name-filter cat -- --all

$ git filter-branch --force --index-filter 
  'git rm --cached --ignore-unmatch site-cookbooks/java/files/default/usr/local/src/jdk-7u45-linux-x64.rpm' 
  --prune-empty --tag-name-filter cat -- --all

$ git filter-branch --force --index-filter 
  'git rm --cached --ignore-unmatch site-cookbooks/mysqld/files/default/usr/local/src/MySQL-5.6.15-1.linux_glibc2.5.x86_64.rpm-bundle.tar' 
  --prune-empty --tag-name-filter cat -- --all

$ git commit --amend -CHEAD

I regained my composure and git pushed, and it was successful.

$ git push -u origin master
Counting objects: 533, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (439/439), done.
Writing objects: 100% (533/533), 79.03 MiB | 5.44 MiB/s, done.
Total 533 (delta 119), reused 0 (delta 0)
To git@github.com:Isaoxxxx/xxx-chefrepo.git
 * [new branch]      master -> master
Branch master set up to track remote branch master from origin.

When I checked github, the registration was successful.

Response to uploading files that should not be uploaded

When I checked, I accidentally uploaded data_bag_key along with it, so I deleted it on github. Since I edited it in the browser, this time I got an error that I couldn't push unless I merged it. The wind is competing.

$ git push -u origin master
To git@github.com:Isaoxxxx/xxx-chefrepo.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'git@github.com:Isaoxxxx/xxx-chefrepo.git'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes before pushing again.  See the 'Note about
fast-forwards' section of 'git push --help' for details.

How do you merge? So after a little research, it seemed that it would be better to fetch, pull, and push for the time being. Pull is the equivalent of fetch + merge internally.

When I git pulled in this state, the local file disappeared as expected. In the first place, this key is just a copied backup file and has been registered in .gitignore, so I copied it back

$ cp -p .. /.chef/encrypted_data_bag_secret  ./data_bag_key
$ cat .gitignore
/cookbooks/
data_bag_key

Even if you try '$ git status', there is no update file. So when I checked from the browser with 'git push', the updated '.gitignore' was updated, and I couldn't find the 'data_bag_key' I deleted and added to '.gitignore', so it seems to have been as intended.

When you upload a file that shouldn't be uploaded, instead of deleting it from the browser, you can do it with a command, if you accidentally add a file that shouldn't be published to git. I used it as a reference.

git filter-branch --index-filter 'git update --index --remove "filename" ' HEAD
git commit -a
git push ...

It seems that it is better to do it like that.

Conclusion

Once you update your local repository, you can use the

git add
git commit -m "history"
git push

If you update in a remote repository

git fetch
git pull

Add files you don't want to share in your local repository to '.gitignore' If you delete the entire file after 'adding' in your local repository and before 'commit', you can use the

git rm filename

If you delete only the index after adding in the local repository and before commit,

git reset HEAD -- <file>

Reverse lookup was also convenient. Basic Operations | Reverse Git | Introduction to Git that Even Monkeys Can Understand - Let's Master Version Control - As a chef, it seems that you need to write the README properly to make it easier to use.

Currently, I mainly use gitlab. This does not mean that closed is particularly preferable.

Thank you for reading. Here is the following.

Related Articles