GitHub is a commonly used code management warehouse, which is convenient for us to manage code version update iterations. For rookies, it also helps to get the code information written by yourself anytime and anywhere, and share and communicate with others.
The rookie tutorial has a very comprehensive description, here the operation is simplified into a direct process:
The general workflow is as follows:
- Clone the Git resource as a working directory.
- Add or modify files on the cloned resource.
- If other people make changes, you can update the resources.
- Review the changes before submitting.
- Submit changes.
- After the modification is completed, if an error is found, you can withdraw the submission and modify and submit again.
The following content is copied from the rookie tutorial "Git Five-Minute Tutorial" and modified based on my own practice
https://www.runoob.com/w3cnote/git-five-minutes-tutorial.html
getting Started
Before using Git, you need to create a repository. You can use an existing directory as a Git repository or create an empty directory.
It is recommended to create a new folder locally and a new warehouse on GitHub. Starting from scratch, it is easier to understand the whole process.
1. Initialize the local warehouse
First, after the git tool is installed, use the git bash tool to open (cd) to the current working directory (the related file operation is similar to linux). Use your current directory as the local directory of the Git repository , we just need to initialize it.
git init
Use our designated directory as the Git repository. After completing the initialization, there will be a hidden .git file directory below.
git init folderpath
From now on, we will assume that you are in the root directory of the Git repository, unless otherwise stated.
2. Add new files
We have a warehouse, but nothing. You can use the add command to add files.
git add filename
You can use add... to continue adding task files. You can also use git add. Add all files in the directory.
3. Submit version
Now that we have added these files, we hope that they can actually be stored in the Git repository.
For this, we submit them to the warehouse.
git commit -m "Adding files"
If you do not use -m, an editor will appear to let you write your own comment information.
When we modify a lot of files, and don't want to add each one, and want to commit to automatically submit local modifications, we can use the -a flag.
git commit -a -m "Changed some files"
The -a option of the git commit command can submit all modified or deleted documents that have been managed by git to the repository. The repository here is still locally and has not been published to GitHub.
Be careful, -a will not cause a new file to be submitted, it can only be modified.
4. Release version
Let's clone a library from the server first. This library can be a new library we manually created on GitHub to get the address of the new library .
git clone ssh://example.com/~/www/project.git
Now we can push to the server after the modification.
git push ssh://example.com/~/www/project.git
5. Get back updates
If you have pushed as above, the following command indicates that the current branch is automatically merged with the only tracking branch.
git pull
Update from a non-default location to the specified url.
git pull http://git.example.com/project.git
After executing this step, the code finally arrives in the GitHub repository
**Additional content
6. Delete
If you want to delete files from the repository, we use rm.
git rm file
7. Branch and merge
The branch is done locally and is fast. To create a new branch, we use the branch command.
git branch test
The branch command does not bring us into the branch, it just creates a new branch. So we use the checkout command to change the branch.
git checkout test
The first branch, or master branch, is called "master".
git checkout master
Changes to other branches will not be reflected on the main branch. If you want to commit changes to the master branch, you need to switch back to the master branch and then use merge.
git checkout master git merge test
If you want to delete a branch, we use the -d flag.
git branch -d test