[RUBY] 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.