Common operations on github

 Construction of Git and GitHub environments under Linux

 

 

Step 1: Install Git, use the command "sudo apt-get install git"

 

 

Step 2: Go to GitHub to create a GitHub account

 

 

Step 3: Generate ssh key, use the command "ssh-keygen -t rsa -C "[email protected]"", your_email is your email

 

 

Step 4: Go back to github, enter Account Settings, select SSH Keys on the left, Add SSH Key, fill in the title, and paste the key. key is

~/.ssh/id_rsa.pub contents.

 

Step 5: Test whether the ssh key is successful, use the command "ssh -T [email protected]", if you've successfully authenticated, but GitHub does not provide shell access appears. This means that you have successfully connected to github.

 

 

Step 6: Configure Git configuration file, username and email

 

 

git config --global user.name "your name" //Configure username

 

 

git config --global user.email "your email" //配置email

 

 

 

 

 

2 Using Git to upload from local to GitHub

 

 

Step 1: Enter the directory where you want to upload the file and enter the command "git init"

 

 

Step 2: For example, if you want to add a file xxx to the local warehouse, use the command "git add xxx", you can use "git add ." to automatically determine which files to add

 

 

Step 3: Then submit this addition to the local repository, and use the command "git commit -m " to describe this commit " "

 

 

Step 4: Create a local repository origin, use the command "git remote add origin [email protected]:yourName/yourRepo" youname is your GitHub username, yourRepo is the repository you want to upload to GitHub, this is where you are Repositories added on GitHub.

 

 

Step 5: Finally, submit the origin of the local warehouse to the remote GitHub warehouse, use the command "git push -u origin master", only add the -u parameter for the first time

 

 

 

 

3 Update code

 

The first step: git status to view the changes in the code

 

Step 2: git add . Automatically determine which files to add

 

Step 3: git commit -m Enter the information to submit the modification

 

Step 4: git push origin master Submit to remote warehouse

 

 

 

4 Clone project from GitHub to local

 

 

Step 1: Go to a repository on GitHub and copy the "HTTPS clone url" on the right

 

 

Step 2: Go back to the directory to be stored and use the command "git clone https://github.com/chenguolin/scrapy.git", the red url is just an example

 

 

Step 3: If the local version is not the latest, you can use the command "git fetch origin", origin is the local repository

 

 

Step 4: Merge the updated content into the local branch, you can use the command "git merge origin/master"

 

 

 

 

 

If you don't want to merge manually, then you can use: git pull <local repository> master // This command will pull the latest version and merge it automatically

 

 

 

 

 

5 GitHub branch management

 

 

create

 

 

Step 1: Create a local branch: git branch <new branch name>

 

 

Step 2: Switch to the newly created branch: git checkout <new branch name> --------------- Create + switch branch: git checkout -b <name>

 

 

Step 3: We merge the work results of the dev branch into the master branch git merge dev ------ The git merge command is used to merge the specified branch into the current branch

 

 

Step 4: After the merge is complete, you can safely delete the dev branch: git branch -d dev

 

 

Step 5: Synchronize the local branch to GitHub: git push <local repository name> <new branch name>

 

 

Step 6: Add a new remote to your branch: git remote add <remote name> <address>

 

 

 

 

delete

 

 

1 Delete a branch locally: git branch -d <branch name>

 

 

2 Sync to GitHub to delete this branch: git push <local repository name> :

 

 

 

 

 

5 common mistakes

 

 

1 If the error is ERROR: Repository not found.fatal: The remote end hung up unexpectedly, it means that the url link of your origin is wrong, it may be a creation error, or it may be this [email protected]:xxx/new-project The .git url was specified incorrectly. rebuild.

Guess you like

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