Hello everyone.
Previously, I explained the commands of Github over two articles.
Let's understand github! ① Let's understand github! ②
However, even if you understand the meaning of the command, there is not much information that you can understand the specific flow from creating a new repository on Github to managing it. So, this time, I'll try to manage the Xcode project on Github and use the simple branch and commit functions!
*** * The content I will tell you this time may be easy to do on the X code, but in pursuit of clarity, this time it is an article for those who want to manage anything on GitHub. I will. Please note. *** ***
Before reading this article, I encourage you to take a closer look at Git from the beginning! https://github.com/takanabe/introduction-to-git
・ Xcode --11.3.1
・ Git --2.26.0
· CLI-Terminal
First, let's create an X Code project! You don't have to do anything special here, so feel free to name and create the file.
*** I created a file called GithubTest! ***
Next, let's open the terminal!
When you open the terminal, you should see something like the following.
Terminal
○○○○○@xxxxxxxxxxMBP ~ %
Type the displayed *** "cd" *** command and drag and drop the created Xcode project to the terminal! !! By the way, *** "cd" *** is an abbreviation for *** change directory ***
Terminal
○○○○○@xxxxxxxxxxMBP ~ % cd /Users/File creator/Desktop/GithubTest
*** Put the file in the terminal and press enter! !! *** ***
Then the terminal will recognize the file.
Terminal
○○○○○@xxxxxxxxxxMBP ~ GithubTest %
Decide your own username and email address
Terminal
git config user.name Yamada Taro //The name of the person who works
//enter
git config user.email [email protected] //My email address
//enter
This time, I registered with Taro Yamada
This completes the initial settings.
Visit Github! https://github.com/join
If you haven't created a Github account, register. Although it is in English, it is fairly easy to register.
If you can register, you will be confused by the various functions, but one is important. What you do on Github is to create a new repository.
If you have registered, you will find a *** new *** button on the top left of Github. Click on it.
Then you will see a screen like the one in the picture below.
Let's decide the Repository name! I made it the same as the Xcode file name. Check public, you don't need to check the item of Initialize this repository with.
If you see the screen below, you are successful!
Simply put, just execute the command in the *** ... or create new repository on the command line *** part of the picture below. You can manage your X Code project on GitHub.
Let's type the following commands in order
git init
The git init command is a command to initialize. Think of it as a signal that you're going to type in the git command from now on.
Terminal
○○○○○@xxxxxxxxxxMBP ~ GithubTest % git init
When you execute the command. .. ..
Terminal
Reinitialized existing Git repository in /Users/File creator/Desktop/GithubTest/.git/
If you get a reply like this, the initialization is successful.
git add .
Even if you type it in, you can proceed, but be careful as it will be confusing! !!
Well, let's get back to the story! *** Let's do git add. ***
Terminal
○○○○○@xxxxxxxxxxMBP ~ GithubTest % git add .
*** The git add. *** command is a command to prepare (set) to commit "all the contents of the Github Test file".
Even if you type this command, no message will be returned.
git commit -m ""
Next, we will commit. commit is a command that records repository work. At this stage, I haven't written any code, but you can register even if it is empty, so let's register.
Terminal
○○○○○@xxxxxxxxxxMBP ~ GithubTest % git commit -m "first commit"
"" The contents here can be changed freely. At first, "first commit" is fine.
When you press the enter key, a lot of English comes out, but please be assured that the contents of the X code file are simply read.
Now, let's check if the commit is done properly.
Execute it, and if it looks like the following, the commit is successful.
Terminal
○○○○○@xxxxxxxxxxMBP ~ GithubTest % git graph
* 9e865bb (HEAD -> main) 2020-11-05 Yamada first commit
git branch -M
This command changes the name of the core branch.
Let's implement it for the time being.
Terminal
○○○○○@xxxxxxxxxxMBP ~ GithubTest % git branch -M master //Rename to master
//I will check
○○○○○@xxxxxxxxxxMBP ~ GithubTest % git branch
* master
○○○○○@xxxxxxxxxxMBP ~ GithubTest % git graph
* 9e865bb (HEAD -> master) 2020-11-05 Yamada first commit
**** The branch name is master *** This time, there is no problem with main, so let's proceed with main as it is.
git remote add origin 〜###
Use this command to publish your code.
Terminal
○○○○○@xxxxxxxxxxMBP ~ GithubTest % git remote add origin [email protected]:Your account name/GithubTest.git
There is no particular response from the terminal.
git push -u origin###
This command is used to send the contents of the local repository of the current branch to the remote repository. The local repository here is GithubTest, which I have now. And the remote repository is the file required to publish the contents of the local repository GithubTest to Github.
This is a file on the terminal, so it has no reality.
Let's execute the command for the time being
Terminal
○○○○○@xxxxxxxxxxMBP ~ GithubTest % git push -u origin main
I think that various commands will come out, but ... If the following response is returned at the end, push is successful.
Terminal
Branch 'main' set up to track remote branch 'main' from 'origin'.
The remote repository that does not have the actual situation mentioned above is the origin main.
Let's check it.
Terminal
○○○○○@xxxxxxxxxxMBP ~ GithubTest % GithubTest % git graph
* 9e865bb (HEAD -> main, origin/main) 2020-11-05 Yamada first commit
yamazakishunta@yamazakntanoMBP GithubTest %
origin / main has been added! This is a remote repository. It's a file that doesn't actually exist.
Please note that you must go through a remote repository to upload to Github.
When I update the site on Github. .. ..
By the way, press the green Add a README. You can create a README. Write a brief description of the app in the README.
When implemented, it looks like this.
Did you see this word somewhere? That's right. The git add README.md command. I didn't run the command above as this is added manually.
How was that? It's a lot of work at first, but once you get used to it, it's very simple and you can publish your code.
However, unfortunately, this alone is not enough for application development.
In actual app development, you need to work on or merge branches. In Part 2, I would like to share how to use Github with actual development in mind!
Recommended Posts