Github desktop is useful when you start learning and operate git. Intuitive and easy with GUI! I don't know.
However, according to the story of an active engineer, git operation is done from the terminal!
In this article, for de-Github desktop, I will describe how to operate with terminal!
The structure of this article is as follows.
--Creating a repository --Cut a branch and work
This article is written by a beginner. I would appreciate it if you could comment on any mistakes or incorrect expressions!
【environment】 macOS Catalina 10.15.7 Ruby on Rails 6.0.0 Ruby 2.6.5
[Other] We will proceed on the following assumptions.
--You have an account on GitHub --Implementing rails new and creating an app directory
First, log in to GitHub and create a remote repository.
【manner】 ① Sign in to Github and click "New" next to Repositories (2) Enter the repository name and select whether to publish or not. Then click Create repository. ③ It is OK if the remote repository is created.
【manner】 ① At terminal, move to the application directory. ② Enter the git init command.
git_app % git init
Reinitialized existing Git repository in #When executed, this display appears.
git_app %
For rails, you don't have to type this command. (Because it is automatically initialized when rails new) However, this is not always the case in other languages, so I'm typing it for habit.
③ We will make the first commit. Enter the following command.
git_app % git add .
git_app % git commit -m "first_commit"
Point: Enter the add command before commit. I think add is easy to understand by looking at the image below!
In short, it's like choosing a file to commit. It's like selecting all or some files.
This time I want to select all the changed files, so add "." In addition to git add.
【manner】 Enter the following command to push to the remote repository.
git_app % git remote add origin http://Github.com/Your own Github ID/app name.git
git_app % git push -u origin master
When you push, you will be asked to enter your account name and password, so enter them. Open GitHub and if the commit is reflected, you're done!
When you do something, you cut the branch. The operation used at that time is described.
【manner】 Enter the following command to break the branch.
git_app % git checkout -b "Branch name"
Checkout -b will move to that branch after it is created. By the way, if you want to check the current branch name, enter the following command.
git_app % git branch
*master #On the current branch*Attach
hogebranch
hugabranch
【manner】 Enter the add and commit commands to commit.
git_app % git add . #Specify all changed files
git_app % git commit -m "Implemented for" #Set commit name
git_app % git push origin HEAD #Push to remote repository
By setting it to HEAD, you can guess without writing the branch name. Even if the branch name is long, it is Hetchara.
By the way, When you want to select a file to commit, With -i, you can select files as if you were interacting with them.
git_app % git add -i
staged unstaged path
1: unchanged +1/-2 app/views/layouts/application.html.erb
2: unchanged +1/-1 app/views/layouts/mailer.html.erb
3: unchanged +1/-0 app/views/layouts/mailer.text.erb
*** Commands ***
1: status 2: update 3: revert 4: add untracked
5: patch 6: diff 7: quit 8: help
What now>
You can operate it by entering a number and pressing enter. (Explanation of each function is omitted.)
When selecting a file to commit like this time, Enter 2 and select the file.
What now> 2
staged unstaged path
1: unchanged +1/-2 app/views/layouts/application.html.erb
2: unchanged +1/-1 app/views/layouts/mailer.html.erb
3: unchanged +1/-0 app/views/layouts/mailer.text.erb
Update>> 1 #Enter the numbers of the files you want to commit one by one
staged unstaged path
* 1: unchanged +1/-2 app/views/layouts/application.html.erb
2: unchanged +1/-1 app/views/layouts/mailer.html.erb
3: unchanged +1/-0 app/views/layouts/mailer.text.erb
Update>> #For the selected file*Attach
After making your selection If it is empty, press enter and press 7 or Ctrl + c to exit and commit.
After that, create a pull request from Github and merge it! !!
Thank you very much! !!
-[Introduction to Rails] How to install Github -[Simple explanation] How to use the Git add command -[Git] Basic Command -Simple flow from branch creation using git to push -Flow from rails new to creating repository on GitHub