[LINUX] Git basics

Term (in the process of editing)

commit

An operation in which the user saves a record at any time.

Repository

A place to store commits.

If you want to participate in the development of a project that is already managed by Git, copy (clone) the repository and use it.

Work tree

The location to hold the file to be modified.

Staging area

Where to register the file to commit.

Git directory

Where to store commits.

Steps to get to GitHub

This time, I will omit the explanation of initial settings such as installing Git and creating an account on GitHub.

Imagine a situation where a pre-registered person starts a new project.

Duplicate the remote repository locally or reflect the locally created repository remotely

This time, we will create a repository on GitHub first as a repository on the remote side, and then duplicate it locally.

    $git clone GitHub repository URL

Since the GitHub file is duplicated, move to the copied directory with the cd command.

Create a working branch

In Git, it is basic to create a branch, work on it, and merge it into master when it is completed, so create a branch here.

You can check the current branch with the following command.

    $ git branch
    * master

Use the following command to create a branch.

    $git branch branch name

Example)

    $ git branch work

After creating a branch, switch the branch with the following command

 $git checkout branch name

Example)

    $ git checkout work

After switching branches, edit the file and upgrade the version.

Make a commit

I want to save the rewritten file in the remote repository, so execute the following command.

    $git add filename

The file specified by this command will be the commit target.

This time, we plan to commit all the files in the folder, so execute the following command.

    $ git add .

Now that you are ready to commit, use the following command to commit.

    $ git commit -m 'comment'

This completes the commit. (If you do not add -m, you will be asked to enter a comment on vi.)

Merge branches

This time, work is imported into master.

First, move to the master branch.

    $ git checkout master
    Switched to branch 'master'
    Your branch is up to date with 'origin/master'.

Even if you open the edited file as it is, the change is not reflected because the branch is switched.

Example)

    $ git merge work
    Updating ac63b89..3eefb35
    Fast-forward
    README.md | 1 +
    1 file changed, 1 insertion(+)

If the merge is successful with this command, the edited contents will be reflected in master.

Push remotely

Finally, reflect the changes on GitHub.

Example)

    $ git push origin work
    Counting objects: 3, done.
    Delta compression using up to 4 threads.
    Compressing objects: 100% (2/2), done.
    Writing objects: 100% (3/3), 338 bytes | 338.00 KiB/s, done.
    Total 3 (delta 1), reused 0 (delta 0)
    remote: Resolving deltas: 100% (1/1), completed with 1 local object.
    remote: 
    remote: Create a pull request for 'work' on GitHub by visiting:
    remote:URL of GitHub
    remote: 
URL of To GitHub
    * [new branch]      work -> work

If this is properly reflected on GitHub, it will be successful!

review

The important thing is the following command, and this flow is absolute.

    $ git clone URL
    $ git add .
    $ git commit -m 'comment'
    $ git push origin master

Commands that are useful to know

 $ git status

You can check the current status with this command.

Until you get used to it, you may want to check with this command every time you execute something.

    $ git branch

You can check which branch you are currently in with this command.

Insufficiency

――For development, the flow of local → remote is more natural than the flow of GitHub → Git? ――What happens if you move a file with the branch cut? ――How can I commit a file if I later bring a file in a different directory to the folder?

Recommended Posts

Git basics
Python basics ⑤
Linux basics
Python basics
Python basics ④
Pandas basics
Python basics ③
Python basics
Django basics
Linux basics
Pandas basics
Python basics
Python basics
Python basics ③
Python basics ②
Python basics ②
Python basics: list
Python basics memorandum
Shell script basics # 2
#Python basics (#matplotlib)
Python CGI basics
Python basics: dictionary
Basics of Python ①
Basics of python ①
Python slice basics
#Python basics (scope)
Go class basics
#Python basics (#Numpy 1/2)
#Python basics (#Numpy 2/2)
Unsupervised learning 1 Basics
#Python basics (functions)
Python array basics
Python profiling basics
Linux command basics
git with subprocess.Popen
Python #Numpy basics
Python basics: functions
[Linux] Git command
#Python basics (class)
Python basics summary