In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "how to use the Git client in the Ubuntu system to operate GitHub code", the content of the article is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "how to use the Git client in the Ubuntu system to operate GitHub code" bar!
1. Install Git under Ubuntu
After Ubuntu12.04 LTS, Git has been installed by default, and you can use git-- version to test whether it is installed.
If not, use the command: sudo apt-get install git git-core to install git
II. Ssh certification
Use the ssh command under Ubuntu to connect to github.com 's SSH service with the login name git@github.com (this SSH username is shared by all GitHub users).
The code is as follows:
Ssh-T git@github.com
Prompt after execution: Permission denied (publickey).
This means that we have not set public key authentication correctly in our GitHub account, as shown in the following figure:
Next, create a public / private key pair through the ssh-keygen command under Ubuntu:
The code is as follows:
Ssh-keygen-C "yourname@gmail.com"-f ~ / .ssh/github
Then copy the contents of the ~ / .ssh / github.pub public key to the clipboard. The public key is a long string. Be careful not to add extra spaces or newline characters when pasting, otherwise authentication will fail due to the mismatch between the server and client public keys during the public key authentication process. Finally, copy the correct public key content to the Key text box of GitHub, give the ssh a name, and save it.
After the setup is successful, use Terminal to access GitHub with the ssh command, which displays a message of successful authentication and exits.
The code is as follows:
Ssh-T git@github.com
Prompt after execution: Hi github! You've successfully authenticated, but GitHub does not provide shell access.
After setting up the above steps, you can directly use the git command to access github's code repository.
3. Submit the code to GitHub
First, create a new repo on github.com, add the appropriate .gitignore, LICENSE, etc., as appropriate, and then submit the local code to github
The code is as follows:
Git pull
Get a new version
The code is as follows:
Git status
Git add
Git commit-m "add new files"
Git remote add origin git@github.com:FranFan/php-demo
Git push-u origin master
Finally, a picture is attached, which is very useful.
4. Collection of common operation commands in Git:
1) remote warehouse related commands
Check out the warehouse:
The code is as follows:
$git clone git://github.com/jquery/jquery.git
View the remote warehouse:
The code is as follows:
$git remote-v
Add a remote warehouse:
The code is as follows:
$git remote add [name] [url]
Delete the remote warehouse:
The code is as follows:
$git remote rm [name]
Modify the remote warehouse:
The code is as follows:
$git remote set-url-- push [name] [newUrl]
Pull remote warehouse:
The code is as follows:
$git pull [remoteName] [localBranchName]
Push remote warehouse:
The code is as follows:
$git push [remoteName] [localBranchName]
* if you want to submit a local branch test to the remote repository as a master branch of the remote repository, or as another branch called test, as follows:
The code is as follows:
$git push origin test:master / / submit a local test branch as a remote master branch
$git push origin test:test / / submit a local test branch as a remote test branch
2) commands related to branch operation
View the local branch:
The code is as follows:
$git branch
View the remote branch:
The code is as follows:
$git branch-r
(if you still can't see it, git fetch origin first.)
Create a local branch:
The code is as follows:
$git branch [name]
-Note that the new branch will not automatically switch to the current branch after it is created.
Toggle branches:
The code is as follows:
$git checkout [name]
Create a new branch and immediately switch to the new branch:
The code is as follows:
$git checkout-b [name]
Check out the remote branch directly:
The code is as follows:
$git checkout-b [name] [remoteName]
(e.g. git checkout-b myNewBranch origin/dragon)
Delete the branch:
The code is as follows:
$git branch-d [name]
The-d option can only delete branches that have already participated in the merge, and cannot be deleted for branches that have not been merged. If you want to force the deletion of a branch, use the-D option
Merge branches:
The code is as follows:
$git merge [name]
-merge the branch named [name] with the current branch
Create a remote branch (local branch push to remote):
The code is as follows:
$git push origin [name]
Delete the remote branch:
The code is as follows:
$git push origin: heads/ [name]
Or $
The code is as follows:
Git push origin: [name]
* create an empty branch: (remember to submit changes to your current branch before executing the command, otherwise you will be forced to delete it without regret)
The code is as follows:
$git symbolic-ref HEAD refs/heads/ [name]
$rm .git / index
$git clean-fdx
3) tag operation related commands
View the version:
The code is as follows:
$git tag
Create a version:
The code is as follows:
$git tag [name]
Delete version:
The code is as follows:
Git tag-d [name]
View the remote version:
The code is as follows:
$git tag-r
Create a remote version (local version push to remote):
The code is as follows:
$git push origin [name]
Delete the remote version:
The code is as follows:
$git push origin: refs/tags/ [name]
Merge the tag of the remote warehouse to the local:
The code is as follows:
Git pull origin-tags
Upload the local tag to the remote repository:
The code is as follows:
Git push origin-tags
Create an annotated tag:
The code is as follows:
Git tag-a [name]-m 'yourMessage'
4) Operation commands related to sub-module (submodule)
Add submodules:
The code is as follows:
$git submodule add [url] [path]
Such as:
The code is as follows:
$git submodule add git://github.com/soberh/ui-libs.git src/main/webapp/ui-libs
Initialize the submodule:
The code is as follows:
$git submodule init
-run only once when the warehouse is checked out for the first time
Update submodules:
The code is as follows:
$git submodule update
-you need to run it every time you update or switch branches.
Delete sub-module: (4 steps)
1)
The code is as follows:
$git rm-- cached [path]
2) Edit the ".gitmodules" file to delete the relevant configuration nodes of the sub-module
3) Edit the ".git / config" file to delete the relevant configuration nodes of the sub-module
4) manually delete the remaining directories of the sub-module
5) ignore some files and folders and do not submit
Create a file named ".gitignore" under the repository root, and write unwanted folder names or files, each element on a single line, as shown in
The code is as follows:
Target
Bin
* .db
6) regret medicine
Delete files that are not versioned in the current warehouse:
The code is as follows:
$git clean-f
Restore the warehouse to the previous commit status:
The code is as follows:
$git reset-hard
7) Git pushes multiple remote repositories with one click
Edit the .git / config file for the local warehouse:
The code is as follows:
[remote "all"]
Url = git@github.com:dragon/test.git
Url = git@gitcafe.com:dragon/test.git
In this way, you can use git push all to Push multiple remote repositories with one click.
Thank you for your reading, the above is the content of "how to use the Git client in the Ubuntu system to operate GitHub code". After the study of this article, I believe you have a deeper understanding of how to use the Git client in the Ubuntu system to operate GitHub code. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.