Upload a local project to Github using the terminal command line

Upload a local project to Github using the terminal command line 

For IOS developers, the use of Github is a skill that must be mastered, and there are many ways to upload projects from local to Github. 1 The development tool Xcode configures Git, and Xcode-->Source Control-->Commit ; 2 Use the Github client to upload the code; 3 Use the terminal command line to upload to Github. Among them, my Github address has a configuration manual I made based on the actual project https://github.com/FISHBALL1/Xcode-git , now I will introduce the third method of uploading to Github from the command line, which is also my personal favorite. a method.

Step 1: Create a local git repository

cd to your local project root directory and execute the git command

git init

Step 2: Add all files of the local project workspace to the staging area

git add .

If you want to add the specified file in the project, then change . to the specified file name.  

Step 3: Submit the files in the staging area to the local warehouse

git commit -m ""

Write comments inside the colon

Step 4: Create your own repository on Github, as shown in the figure

Click Create repository below to enter the interface below, and then copy the https address in the address bar

Step 5 : Associate the local repository to Github

  git remote add origin https://github.com/FISHBALL1/DropList

The following URL address is the https address I copied in the fourth step

If there is an error at this step: fatal:remote origin already exists

        Then enter git remote rm origin first, or git pull --rebase origin master to copy the remote things


Step 6: The last step is to upload the code from the local repository to the Github remote repository

git push -u origin master

After the execution, if there is no error, the upload is successful. It should be reminded that the master here is the default branch of Github. If your local current branch is not master, use the git checkout master command to switch to the master branch. If you want to use the local current branch If the branch uploads the code, put the command in the sixth step

        In the master switch to your current branch name can be.

  Upload success interface



             Finally, share some commonly used commands on Github:

Switch branches: git checkout name

Undo changes: git checkout -- file

Delete file: git rm file

Check status: git status

Add records: git add file or git add .

Add description: git commit -m "miao shu nei rong"

Sync data: git pull

Commit data: git push origin name

branch operation

View branch: git branch

Create a branch: git branch name

Switch branches: git checkout name

Create + switch branches: git checkout -b name

        Merge a branch to the current branch: git merge name

Delete branch: git branch -d name

Delete remote branch: git push origin :name

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324609801&siteId=291194637