The existing local projects uploaded to a new git repository method

A non-existing local project uploaded to the new git git repository There are two methods.

A cloned copy +

The first method is relatively simple, direct use of the remote repository pulled locally, then copy their own local projects to go to the warehouse. Then push to a remote repository up to. This method is not applicable to the case of a local project git repository.

Specific steps are as follows:

1, the first cloned

git clone [email protected]:yuanmingchen/tensorflow_study.git
 
  • 1

2, and then copy all the files to their own project just down the clone warehouse

3, the final push to the remote repository to the top:

git push -u origin master
 
  • 1

Second, the forced merger of the two warehouses

The second method is the first project is initialized to a local git repository, and then forced to merge local storage and remote repository, since the two warehouses are two completely different warehouses, so the error will directly pull, pull when needed false plus -allow-unrelated-histories can pull success. This method is suitable for the local project has been the case a git repository.

Specific steps are as follows:

1, the new git repository, the local project is set to a git repository. If the local project is already a git repository, please skip this step. Under the project root directory:

git init
 
  • 1

2, the existing files in the current directory of all added just the new git repository:

git add .
 
  • 1

3, save the file you just added, and write information stored:

git commit -m "push current files"
 
  • 1

4, the local warehouse and remote warehouse associate:

git remote add origin [email protected]:yuanmingchen/tensorflow_study.git
 
  • 1

5, the contents of pull remote repository, updating local repository, use -allow-unrelated-histories ignore local warehouses and remote repository independence, forced merger (key):

git pull origin master --allow-unrelated-histories
 
  • 1

6, the contents of the local repository push to a remote repository:

git push -u origin master
 
  • 1

Then ok.




Third, other git commands

Finally, attach the other commands git:
1. Delete been associated with the remote host

git remote rm origin
 
  • 1

2, to see all the local branch

git branch -a
 
  • 1

3, create a new branch, called xf

git branch xf
 
  • 1

4, the switching branch to branch xf

git checkout xf
 
  • 1

5, the remote branch code to pull local branch: Git pull <remote host name> <remote branch name>: <local branch name>
as: retrieving master branch origin host, combined with local branches xf, enter the command:

git pull origin master:xf
 
  • 1

6, pushing the current branch, git push <remote host name> <local branch name>: <remote branch name>
PS: Note that the wording of the order is a branch push <source>: <destination>, so git pull is < remote branch>: <local branch>, and git push the <local branch>: <remote branch>.
Such as: the local branch xf push master branch origin host, enter the command:

git push origin xf:master
 
  • 1

Guess you like

Origin www.cnblogs.com/presleyren/p/11715218.html