[RAILS] Git branch creation / deletion / convenient command [Git command]

What is a branch

** branch ** is a function that allows you to develop without affecting the project itself by branching from one project. In other words, the history of changes etc. is branched and recorded individually! A branched branch is unaffected by other branches, so you can make multiple changes (implements) in the same repository at the same time. image.png

In this way, we will develop in multiple branches, implement different functions in each branch, and when the implementation is completed (depending on the team and workers), we will merge and proceed with development. ..

Branch creation related

#Check your current branch(In the output*The branch marked with is the current branch)
$ git branch

#Moving branches between locals
$ git checkout [The name of the branch you want to move to]

#Create a new local branch
$ git branch -b [The name of the branch you want to create]

#Create a new local branch based on a remote branch
$ git branch [New branch name] [The original branch name]

Delete branch

1 ⃣ Delete merged branches(If you do not merge, you will get an error, otherwise 2⃣)
$ git branch -d [Branch name]

2 ⃣ Delete the local branch without asking questions
$ git branch -D [Branch name]

Change branch name

#Rename local branch(From hoge to fuga[hoge] [fuga])
$ git branch -m [Current branch name] [New branch name]

#Change the name of the branch you are currently using(If you want to fuga[fuga])
$ git branch -m [New branch name]                                

Local reflection after pull request & merge to integrated branch

#1 ⃣ Move to the branch you want to reflect(If the integrated branch is hoge[Branch name]Is hoge)
$ git checkout [Branch name]

#2 ⃣ Pull the latest version of the remote locally(If you match it with 1⃣[Branch name]Is hoge)
$ git pull origin [Branch name]

#3 ⃣ Reflection in your working branch(When combined with 1⃣2⃣[Branch name]Is hoge)
$ git checkout [Your working branch name]
$ git merge origin/[Branch name]

* 2 If you want to create a new branch after pulling in ⃣
$ git checkout -b [The name of the branch you want to create]

Empty commit (I often forget this command, so instead of a memo,)

An empty commit can be committed without any new or modified files. It is used when checking the branch.

$ git add -A

$ git commit --allow-empty -m "Commit message"

#Push to remote repository
$ git push origin [Branch name]

Finally

This time, there is no memorandum element for the author by the author who is a beginner, but I hope it will be helpful. If there are other frequently used commands, I would like to add them.

Recommended Posts

Git branch creation / deletion / convenient command [Git command]
Ruby on Rails model creation / deletion command
(Git) Basic command