Commit local project code to the Github repository for the first time

One, the required command

git init   // 1. Initialize the project folder

git add .  // 2. Add all files to the staging area

git commit -m "first commit"   // 3. Submit the information to the local repository

git remote add origin XXX     Git branch = git remote rm origin; git branch = git remote rm origin

git pull    // 5. Pull remote primary branch information, first pull merge information

git push -u -f origin master  -f () -f () -f () -f () -f () -f ()

Copy the code

Create a repository on Github

  1. Make sure you have one firstgithubAccount number, if not, you can register first
  2. The logingithub, click your profile picture to pop up, click”Your respositories“That is, your repository;
  3. Click New to create a new warehouse. The new warehouse, originally there was only oneREADME.mdfile
  4. If you do not use the warehouse, you cansettingsTo delete it.

    Delete warehouse operation:

Commit existing projects (local project code) to git repository

In the root directory of the local project, open the CMD program and enter CMD. The daily-demo here is my local project (existing code)

Need to input thecmdCommands and explanations:

  1. Initialize the local repository:git init
  2. Add all files (modified files, new files, etc.) to the staging area:git add .
  3. To commit a staging file to a local repository:Git commit -m
  4. Associate a local repository with a remote repository (connect to a remote repository) :git remote add origin XXX
  5. Pull remote primary branch information and synchronize to local:git pull
  6. Push local repository to remote repository (synchronize code to remote repository) :git push -u -f origin master

Note:

“-u” means to create upStream and push code to Github. In the meantime, this upStream should only be created when the code is first pushed and will not be created in the future

-f (-f) -f (-f) -f (-f) -f (-f) -f (-f

Resolve possible errors:

  1. Error: Failed to push some refs to;

    Causes of the problem:Remote library is inconsistent with local library, so the remote library to the local library can be synchronized, that is, rungit pull --rebase origin masteCommand, push again (execute justgit push origin -u -f origin masterCommand).

  2. To merge updates from remote libraries into local libraries:git pull --rebase origin master

    Rebase cancels local commits and transfers them to the updated repository.

Git remote Add or delete the remote repository address

  1. Git remote add origin git remote add origin To push to the server, add the remote address first:
  2. Git remote -v git remote -v
  3. Git remote remove origin;
  4. Git remote origin set-url XXX
  5. To change the remote warehouse address, delete the remote warehouse address first and then add a new one. Or simply change the remote warehouse address.