GitHub uploads project Steps and FAQs

Source: Internet
Author: User
Tags svn update tag name using git

First of all, the company used in the home company is SVN. About a year has not used GitHub,, and then there are a variety of small problems, in order to let themselves remember, write it out, of course, I also rely on degrees Niang to solve, naturally write is also a year let me see and successfully solved my problem of things.

1. Build a project on GitHub

After logging on to GitHub, you can find a button "New Repository" in the right-hand side, click on it, fill in the project name, description and URL after you can create, then a prompt page, write down a similar [email protected]:xxx/ Xxx.git address, this is the address of your project.

2. Configure Git and upload code

After installing git successfully, if it is under Windows, choose Git Bash, complete everything on the command line, it may begin to be a bit of a hassle, but on the few command lines, remember it a few times. Start with the initial setup of Git:

1 git config--global user.name "Your Real name"
2 git config--global user.email [email protected]

Then start the most troublesome step, you need to upload files to GitHub's git system, you need an SSH key to authenticate, the following starts to generate the key and the commit key. Open git Bash and create SSH key:

1 ssh-keygen-c ' [email protected] '-t RSA

Then you need to enter the location of the SSH key, you can use the default path regardless of the direct return. Enter the password you want, and SSH key will be generated. Now you need to submit this key to GitHub, first open the key save location, there will be three files, find id_rsa.pub, open with a text editor, copy all the characters inside. Go to GitHub and find account Settings in the upper right toolbar. On this page there is an SSH public keys tab, select Add another public key. Title can be filled with a random, key paste just the character, submit.

Once you've done this, you can upload your own code. Find yourself sharing the uploaded code folder, right click to choose Git Bash, or go to this folder in Git bash. Build a warehouse:

1 git init

Select the files to add to the warehouse:

1 git Add.

In general, if you want to share all the code in this folder, add "." After add, the example above is this, if you pass the specified, only need to put "." To the file name, and now just select the files to be added to the warehouse, the following is added into the warehouse:

1 git commit-m ' Test '

-M followed by a parameter indicating that after committing the code to GitHub, the description will be displayed on the code file information, such as where the tag is.

It took so long to start uploading the local repository to GitHub, and the following two lines of command fix the problem:

You need to pull the code first to push the upload success

(Git pull Origin master)

Continue with the following actions

1 git Remote add origin [email protected]: Xxx/xxx.git

2 Git pull Origin Master


3 Git push-u Origin master

This [email protected]:xxx/xxx.git is the address above which the created item is generated. Now open your project URL and you can see that your code has been shown. If you want to update the code, repeat it.

What if you submit sensitive information, such as your own password set in the code or forget to delete the upload up? After re-editing the upload still has a history, and using Git to delete the history of the seemingly troublesome, so the use of delete items, deleted and then re-upload. Delete items need to find the admin button at the top right of the GitHub website, go inside and the bottom right has a delete button, so you can delete it.

Second, Git common commands

1) Remote Warehouse related commands

Checkout warehouse: $ git clone git://github.com/jquery/jquery.git

View remote repositories: $ git remote-v

Add remote repository: $ git remote add [name] [url]

Delete Remote repository: $ git remote RM [name]

Modify remote repository: $ git remote set-url--push [name] [Newurl]

Pull remote repository: $ git fetch [remotename] [Localbranchname]

Push remote repository: $ git push [remotename] [Localbranchname]

* If you want to submit a local branch test to the remote repository as the master branch of the remote repository, or as another branch called Test, as follows:

$git Push Origin Test:master//submit local Test branch as remote Master Branch

$git Push Origin test:test//submit local test branch as remote Test branch

2) Branch (branch) operation related commands

View local branch: $ git Branch

View Remote branch: $ git branch-r

Create local branch: $ git branch [name]----Note that the new branch will not automatically switch to the current branch after it is created

Switch Branch: $ git checkout [name]

Create a new branch and switch immediately to the new branch: $ git checkout-b [name]

Delete Branch: $ git branch-d [name]-----D option can only delete branches that have already joined the merge and cannot be deleted for branches that do not have a merge. If you want to forcibly delete a branch, you can use the-D option

Merge branch: git merge [name]----Merge the branch with the name [name] with the current branch

Create a remote branch (local branch push to remote): $ Git push origin [name]

Delete Remote branch: git push origin:heads/[name] or $ gitpush origin: [Name]


* Create an empty branch: (Before executing the command remember to submit your current branch of the changes, otherwise it will be forced to delete the clean without regret)

$git symbolic-ref HEAD Refs/heads/[name]

$rm. Git/index

$git CLEAN-FDX

3) version (tag) operation related commands

View version: $ git tag

Create version: $ git tag [name]

Delete version: $ git tag-d [name]

View remote version: $ git tag-r

Create a remote version (local version push to remote): $ Git push origin [name]

Delete Remote version: $ git push origin:refs/tags/[name]

Merge the remote repository's tag to local: Git pull Origin--tags

Upload local tag to remote repository: $ Git push origin--tags

Create annotated tag:$ git tag-a [name]-M ' YourMessage '

4) Sub-module (submodule) Related Operations Command

Add sub-module: $ git submodule add [url] [path]

Example: $git submodule add Git://github.com/soberh/ui-libs.git src/main/webapp/ui-libs

Initialize submodule: $ git submodule init----run only once when the warehouse is first checked out

Update submodule: git submodule update----need to run every time you update or switch branches

To delete a submodule: (4 steps away OH)

1) $ git RM--cached [path]

2) Edit the ". Gitmodules" file to delete the relevant configuration node of the Submodule

3) Edit the ". Git/config" file to delete the relevant configuration node of the Submodule

4) Manually delete the remaining sub-modules directory

5) Ignore some files, folders do not submit

Create a file with a name of ". Gitignore" under the repository root and write an unwanted folder name or file with one line per element, such as

Target

Bin

*.db

Three, Git command detailed

Now that we have the local and remote repositories, let's try using Git's basic commands:

Git Pull: Updates the code locally from other repositories (both remote and local), for example: ' Git pull Origin master ' is updating the code for the Origin repository to the local master primary branches, This feature is similar to the SVN update

Git add: is to add the current changes or new files to the Git index, added to the Git index is recorded in the version history, this is a step before committing, such as ' git add app/model/user.rb ' will increase app/model/ USER.RB file into the git index, which is similar to the SVN add

git rm: Removes files from the current workspace and index, such as ' git rm app/model/user.rb ', which is similar to SVN's RM, Del

Git commit: Commit changes to the current workspace, similar to the SVN commit command, such as ' Git commit-m story #3, add user Model ', which must be submitted with-m to enter a commit message, This feature is similar to the SVN commit

Git push: Updates the local commit code to the remote repository, such as ' Git Push origin ', which updates the local code to the remote repository named Orgin

git log: View the history log, which is similar to the SVN log

git revert: Restore a version of the changes, you must provide a specific git version number, such as ' git revert bbaf6fb5060b4875b18ff9ff637ce118256d6f20 ', git version number is a generated hash value

The commands above are almost all common to each version control tool, so let's try some of the git-unique commands:

Git branch: Adding, deleting, checking, and so on, for example ' git branch new_branch ' will create a new branch called New_branch from the current working version, ' Git branch-d new_branch ' will force the deletion called New _branch's branch, ' Git branch ' will list all the local branches

Git Checkout:git's checkout has two functions, one is to switch between different branch, such as ' Git checkout new_branch ' will switch to New_branch branch, and another function is to restore the function of the Code, For example ' git checkout app/model/user.rb ' will update the user.rb file from the last committed version, and all uncommitted content will be rolled back

Git rebase: Explained in the following two diagram will be more clear, after the rebase command executes, it is actually to move the branch from C to G, so that the branch has a function from C to G

Git Reset: The current working directory is completely rolled back to the specified version number, assuming that we have a-g five commits, where C is the version number Bbaf6fb5060b4875b18ff9ff637ce118256d6f20 (git log can get), We executed ' git reset bbaf6fb5060b4875b18ff9ff637ce118256d6f20 ' so there was only one a-c three commits left.

Git stash: Put the current uncommitted work into the GIT work stack, when the time is ripe to apply back, here for the moment to mention the use of this command, the following in the tip of the key to explain

git config: This command allows you to add and change various git settings, such as ' git config branch.master.remote origin ' to set the remote repository of master to an alias called the Origin repository. This command will be used to personalize your git and create a unique git for you.

git tag: You can tag a specific version so you don't have to memorize a complex version number hash, for example you can use ' git tag revert_version Bbaf6fb5060b4875b18ff9ff637ce118256d6f20 ' to mark this version that you restored, then you can use the revert_version tag name instead of the hash value when you want to view the version later

Git's ability to provide convenient local branching features is related to its file storage mechanism. Git stores versioning information using its own set of file system storage mechanisms, with a. git folder under the code root, with a directory structure like this:

There are several important files and directories to explain: The head file holds the root node information, in fact, the directory structure represents a tree structure, Git uses this tree structure to store version information, then head represents the root The refs directory stores all the different references you have in the current version control directory (refers to the information about the branches of each tree that you use locally and remotely), and it has heads, remotes, stash, tags, four subdirectories, stored separately for different roots, remote repository, Git stacks and tags are four kinds of references, you can use the command ' git show-ref ' to see the reference information more clearly; The Logs directory stores log information based on different references. As a result, git only needs the. Git directory under the code root to record the full version control information, not the root directory and subdirectories like SVN. SVN directory. So here's a look at the difference between git and SVN.

Some of the issues that you may encounter are resolved:

If you enter Git remote add origin [email protected]:d Jqiang (GitHub account name)/gitdemo (project name). Git
Tip error Message: Fatal:remote origin already exists.
The solution is as follows:
1. First enter GIT remote RM origin
2, then enter the GIT remote add origin [email protected]:d Jqiang/gitdemo.git will not error!
3. If you enter GIT remote RM origin or an error, error:could not remove config section ' Remote.origin '. We need to modify the contents of the Gitconfig file
4. Find your GitHub installation path, mine is C:\Users\ASUS\AppData\Local\GitHub\PortableGit_ca477551eeb4aea0e4ae9fcd3358bd96720bb5c8\ etc
5, find a file named Gitconfig, open it to the [remote "origin"] that line to delete the good!

If you enter $ ssh-t [email protected]
Error message: Permission denied (PublicKey). Because the newly generated key cannot join SSH, it will cause the connection to not be on GitHub.
The solution is as follows:
1, first enter $ ssh-agent, and then enter $ Ssh-add ~/.ssh/id_key, so you can.
2, if still do not, enter Ssh-add ~/.ssh/id_key command after the error could not open a connection to your authentication agent. The workaround is key with the Git GUI SSH tool Generated, so that when the key is stored directly in SSH, do not need to ssh-add command to join, and other user,token and other configurations are done with the command line.
3, it is best to check if you copy the contents of the Id_rsa.pub file there is no extra space or blank lines, some editors will help you add these.

If you enter a GIT push origin master
Tip error message: error:failed to push som refs to ....
The solution is as follows:
1. First enter the GIT pull Origin master//start the remote server github file down
2. Then enter $ GIT push origin master
3. If an error occurs FATAL:COULDN ' t find remote ref Master or fatal: ' Origin ' does not appear to be a git repository and fatal:could not Read from remote repository.
4. You need to re-enter git remote add [email protected]:d Jqiang/gitdemo.git
The process of using Git to create a project locally
$ makdir ~/hello-world//Create a project Hello-world
$ CD ~/hello-world//Open this project
$ git init//initialization
$ Touch README
$ git Add Readme//Update Readme file
$ git commit-m ' first commit '//submit update and Comment message "First commit"
$ git Remote add origin [email protected]:d efnngj/hello-world.git//Connect remote GitHub Project
$ GIT push-u origin master//update local project to GitHub project

GitHub uploads project Steps and FAQs

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.