An operation in which the user saves a record at any time.
A place to store commits.
If you want to participate in the development of a project that is already managed by Git, copy (clone) the repository and use it.
The location to hold the file to be modified.
Where to register the file to commit.
Where to store commits.
This time, I will omit the explanation of initial settings such as installing Git and creating an account on GitHub.
Imagine a situation where a pre-registered person starts a new project.
This time, we will create a repository on GitHub first as a repository on the remote side, and then duplicate it locally.
$git clone GitHub repository URL
Since the GitHub file is duplicated, move to the copied directory with the cd command.
In Git, it is basic to create a branch, work on it, and merge it into master when it is completed, so create a branch here.
You can check the current branch with the following command.
$ git branch
* master
Use the following command to create a branch.
$git branch branch name
Example)
$ git branch work
After creating a branch, switch the branch with the following command
$git checkout branch name
Example)
$ git checkout work
After switching branches, edit the file and upgrade the version.
I want to save the rewritten file in the remote repository, so execute the following command.
$git add filename
The file specified by this command will be the commit target.
This time, we plan to commit all the files in the folder, so execute the following command.
$ git add .
Now that you are ready to commit, use the following command to commit.
$ git commit -m 'comment'
This completes the commit. (If you do not add -m, you will be asked to enter a comment on vi.)
This time, work is imported into master.
First, move to the master branch.
$ git checkout master
Switched to branch 'master'
Your branch is up to date with 'origin/master'.
Even if you open the edited file as it is, the change is not reflected because the branch is switched.
Example)
$ git merge work
Updating ac63b89..3eefb35
Fast-forward
README.md | 1 +
1 file changed, 1 insertion(+)
If the merge is successful with this command, the edited contents will be reflected in master.
Finally, reflect the changes on GitHub.
Example)
$ git push origin work
Counting objects: 3, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 338 bytes | 338.00 KiB/s, done.
Total 3 (delta 1), reused 0 (delta 0)
remote: Resolving deltas: 100% (1/1), completed with 1 local object.
remote:
remote: Create a pull request for 'work' on GitHub by visiting:
remote:URL of GitHub
remote:
URL of To GitHub
* [new branch] work -> work
If this is properly reflected on GitHub, it will be successful!
The important thing is the following command, and this flow is absolute.
$ git clone URL
$ git add .
$ git commit -m 'comment'
$ git push origin master
$ git status
You can check the current status with this command.
Until you get used to it, you may want to check with this command every time you execute something.
$ git branch
You can check which branch you are currently in with this command.
――For development, the flow of local → remote is more natural than the flow of GitHub → Git? ――What happens if you move a file with the branch cut? ――How can I commit a file if I later bring a file in a different directory to the folder?
Recommended Posts