Basic Git Command Summary

Basic git command summary.

It is hard to see because it was originally made for me.



init

$ git init

Create a repository in the directory.

$ git init --bare

Create Bare Repository

$ git init --shared

Enable group write permission.



add

$ git add [filename]

Index files and directories.

$ git add -A

Add the contents of the work tree including all changes to the index.

$ git add -u

Only files that I have committed before are added to the index.



commit

$ git commit

Commit the file added to the index.

$ git commit -m “[comment]”

Specify commit message at the same time.

$ git commit -a

Add the changed file (excluding new) to the index and commit it.

$ git commit --amend

Correct the last commit.



status

$ git status

It shows which file was changed compared with the previous commit.



log

$ git log

Refer to the commit log.

$ git log --oneline

Display the first 7 digit commit ID of the commit log.

$ git log --decorate

Specify the position of the HEAD of the commit log.

$ git log --graph

Display the commit log in a vertical graph.

$ git log --grep [filter]

Displays the commit that the specified character is included in the commit log.



diff

$ git diff

Display difference between index and working tree.

$ git diff --cache

Display difference between HEAD and index.

$ git diff [commit id 1] [commit id 2]

Display differences between commits.



checkout

$ git checkout [commit id] [filename]

Restore the committed past files.

$ git checkout [branch]

Change the branch.

$ git checkout --ours [filename]

When conflicting by merging, specify the information and adopt the file contents.

$ git checkout --theirs [filename]

When conflicting with merging, designate the bottom and adopt the file contents.



show

$ git show

Display the latest commit content.

$ git show [tagname]

Specify the tag and display the commit contents.



reset

$ git reset [commit id]

Set the index to the current HEAD state.

$ git reset HEAD [filename]

Unstage the file from the index.

$ git reset --hard [commit id]

Restore all the work tree including the work tree to the commit ID state.

$ git reset --hard HEAD@{[number]}

Return to the state of the number confirmed by git reflog.

$ git reset --hard ORIG_HEAD

Return to the previous state.



rm

$ git rm [filename]

Delete files from work tree and index.

$ git rm --cache [filename]

Delete index file.



mv

$ git mv [filename 1] [filename 2]

Change the file name (when the file exists in the index and work tree)



revert

$ git revert [commit id]

Cancel the commit of the commit ID.



rebase

$ git rebase -i [commit id]

A commit is displayed in order from the commit ID in the order of committing, and if you delete the commit line, you can cancel the commit and if you replace the first pick with another one, you can edit the commit message etc.

$ git rebase --abort

Cancel editing of the previous git rebase.

$ git rebase --continue

adapt git rebase change.



clone

$ git clone [repository PATH] [new repository PATH]

Copy the repository.



push

$ git push [remote repository PATH] [branch]

Write changes to the remote repository.

$ git push [remote repository] --tags

Upload all tags to the remote repository.

$ git push [remote repository] [tagname]

Upload the specified tag to the remote repository.

$ git push [remote repository] :[branch or tagname]

Deletes the specified branch or tag from the remote repository.



pull

$ git pull [remote repository PATH] [branch]

Capture changes in the remote repository.



remote

$ git remote

List remote repositories

$ git remote add [username] [remote repository PATH]

Associate name with remote repository (add remote repository).

$ git remote rename [remoterepository] [new name]

Change the name of the remote repository.

$ git remote show [remote repository]

See the remote repository information.

$ git remote prune [remote repository]

Delete branches excluded from remote repositories locally.



fetch

$ git fetch [remote repository]

Add the latest information on the remote repository.

$ git fetch --prune

Update the deletion information of the remote repository locally.



branch

$ git branch &[new branch]

Confirm the current branch & amp; Create a new branch.

$ git branch -a

Check all branches.

$ git branch -r

Check the remote branch.

$ git branch -d [branch]

Delete the branch.

$ git branch -m [branch] [new branchname]

Change the name of the branch.

$ git branch --set-upstream [my branch] [other branch]

Associate your branch with the branch of another user.



merge

$ git merge [branch]

Merge the current branch with other branches.



tag

$ git tag

Display a list of tags.

$ git tag -n[number]@

Display a list of tags and their message [Specify number of lines] list (1 line when no line number is specified).

$ git tag -l [filter]

Display the tag with a filter.

$ git tag [tagname]

Associate the tag with the current commit ID.

$ git tag [tagname] [commit id]

Associate the tag by specifying the commit ID.

$ git tag -a [tagname]

Associate the message tag with the current commit ID.

$ git tag -d [tagname]

Deletes the specified tag.



stash

$ git stash

Save the current state.

$ git stash save “[message]”

Save the current state with a message.

$ git stash list

Display a list of saved states.

$ git stash pop

Restore the latest saved state.

$ git stash pop stash@{[numbar]}

Specify the number and restore the saved state.

$ git stash apply

Restore the latest saving state while keeping the saved state in the list.

$ git stash apply stash@{[number]}

Restore the preservation state of the specified number while keeping the saved state in the list.

$ git stash drop stash@{[number]}

Delete the saved state.

$ git stash clear

Delete all saved state.



reflog

$ git reflog

Display the commit list that HEAD was pointing in the past.

$ git reflog [branch]

Designate a branch and display the commit list that HEAD was pointing in the past.



cherry-pick

$ git cherry-pick [commit id]

Copy the commit of another branch to the current branch.



config

$ git config -l

Display the configuration of the repository to be used.

$ git config --global user.name [username]

User name setting.

$ git config --global user.email [email address]

Mail address setting.

$ git config --global color.ui auto

Color output results.

Leave a Reply