감동, 마음이 움직이는 것

[How to use git] 본문

Tips (Utility, Computer Language, and etc.)

[How to use git]

Struggler J. 2017. 1. 25. 19:28

First step: making SSH keys

ssh-keygen -t rsa -C "hjpark@evolbio.mpg.de"#Creates a new ssh key using the provided email # Generating public/private rsa key pair...

cat ~/.ssh/id_rsa.pub # ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC6eNtGpNGwstc....




Second step: create a new project

https://git-scm.com/book/en/v2/Git-on-the-Server-GitLab

The first thing you’ll want to do with GitLab is create a new project. This is accomplished by clicking the “+” icon on the toolbar. You’ll be asked for the project’s name, which namespace it should belong to, and what its visibility level should be. Most of what you specify here isn’t permanent, and can be re-adjusted later through the settings interface. Click “Create Project”, and you’re done.

[CF] How to add the clone existing resp

Once the project exists, you’ll probably want to connect it with a local Git repository. Each project is accessible over HTTPS or SSH, either of which can be used to configure a Git remote. The URLs are visible at the top of the project’s home page. For an existing local repository, this command will create a remote named gitlab to the hosted location:

$ git remote add gitlab https://server/namespace/project.git

If you don’t have a local copy of the repository, you can simply do this:

$ git clone https://server/namespace/project.git


[CF] In case you don't want to keep track the changes of files: Use .gitignore file 

It is useful to have a gitignore-file that tells git which type of files it should not keep track of. For example Mathematica-files have caused problems when having a shared project. Or maybe you have many text files that you don't want to share. To do that, open the terminal in the folder where your project is located and create a file with the name '.gitignore' by typing in mate .gitgnore (if you have TextMate installed. Otherwise try vim .gitignore). Now you for example write into the file:

*.nb *.txt

Save and close.

Remember the hints below to avoid conflicts.




Third Step: git status & git pull & git add &git commit & git push

 한국어로 된 이런 사이트도 있다. 

https://backlogtool.com/git-guide/kr/

https://git-scm.com/book/ko/v1/Git%EC%9D%98-%EA%B8%B0%EC%B4%88-%EC%88%98%EC%A0%95%ED%95%98%EA%B3%A0-%EC%A0%80%EC%9E%A5%EC%86%8C%EC%97%90-%EC%A0%80%EC%9E%A5%ED%95%98%EA%B8%B0

https://rogerdudler.github.io/git-guide/index.ko.html

You can check the status of files (staged or unstaged ...) using git status.

More detailed explains are available above links. 


Before push your changes, pull the changes first to avoid conflict.

$git pull #update all the files up to the latest changes


[그림출처] https://rogerdudler.github.io/git-guide/index.ko.html


$git add "files..." #before commit add the files on staged. 

$git status #check your file status

$git commit -m "brief description of the files" #commit your adding changes using brief description

$git push #send your changes for the server


[CF] git diff

git diff shows the difference between two commits or head and working directory.

http://veerasundar.com/blog/2011/06/git-tutorial-comparing-files-with-diff/

https://blog.outsider.ne.kr/1011


Between working directory and HEAD: git diff HAED filename

Between two commits : git diff commit commit 

For example, 

$git diff HEAD^^ HEAD filename #HEAD^^ means two commits back

http://stackoverflow.com/questions/3338126/how-to-diff-the-same-file-between-two-different-commits-on-the-same-branch


using options:

--color-words : changes of the words denoted as a color

--word-diff : apparently show which words are removed and added