Git commands that new engineers should look back on [updated from time to time]

Check where you are on the branch right now

$ git branch

Now you can even create and move branches.

$ git checkout -b [Branch name]

You can delete a branch that you don't have now.

$ git branch -D [Branch name]

This will get the data from other repositories. If you want to get remote data, you can usually go with [origin].

$ git fetch [Repository]

I want to work on someone's branch ...

$ git checkout [The name of the branch someone was working on]

You can now delete the last commit. It can be used when you accidentally push to master.

$ git reset --hard HEAD^

PUSH. origin is a remote repository. For the branch name, enter the name of the branch you are working on. → After that, create a pull request on GIthub or Gitlab.

$ git push origin [Branch name]

Stage the modified file. Although I recognize that, it seems to be deep.

$ git add -A

The one who can easily enter a message when committing.

$ git commit -m “[Write a commit message]"

Stage all files in the working tree

$ git add .

Stage all changes and deletions of Git managed files. (Ignore new files.)

$ git add -u
$ git add --update

And stage all files in the working tree. Reflects files in all working trees with no arguments.

$ git add --all
$ git add -A 

Now you can only add bookmark.rb to the staging area.

$ git add api/app/models/bookmark.rb

Reference article about git add https://www-creators.com/archives/4939

When you want to cancel the last commit. By setting —hard, the changed contents are also canceled.

If you change this —hard part to —soft, the changes will remain and only the commit will be undone.

$ git reset --hard HEAD^

Bring the latest Remote master locally

$ git pull origin master

★ It's important to always keep the master branch new ...

Then checkout to go to your working branch. And

$ git merge origin master

You can capture the latest changes in the master branch. Then a conflict occurs → Command + click to open the conflicting file. You can decide which changes to keep or to apply both changes.

We will update it from time to time. Please point out any mistakes.

Recommended Posts

Git commands that new engineers should look back on [updated from time to time]
[Updated from time to time] Links that are indebted
[Updated from time to time] Ruby on Rails Convenient methods
Memorandum Poem (updated from time to time)
Summary of results of research on object orientation [Updated from time to time]
[Reverse lookup] Spring Security (updated from time to time)
SpringBoot useful site collection (updated from time to time)
Touch all Spring "Guides" (updated from time to time)
[Eclipse] Summary of environment settings * Updated from time to time
I'll forget to look it up, so I've put together a list of frequently used Docker commands [updated from time to time]
Catch up on new features from Java 7 to Java 9 at once
Personally recommended Intellij IDEA initial settings (updated from time to time)