git command line summary
Upload/common
Command Line | content |
---|---|
git clone http://www.xxx.com/aaa/bbb | Pull the code from the server |
git pull | Local and server side synchronization |
git add . | Add all files to the staging area |
git commit -m “xxx” | Add xxx information |
git push | Push the local branch to the server. |
common
Command Line | content |
---|---|
git add [file name] | Add a file to git index |
git branch | View all local branches |
git branch -a | View all branches |
git branch -r | View all remote branches |
git branch -D branchname | Delete branch (cannot delete the current branch) |
git commit -v | When you use the -v parameter, you can see the difference in commit |
git commit -m “xxx” | Add xxx information |
git commit -m “remove” | Remove file (delete from Git) |
git diff --cached 或 git diff --staged | View updates that have not yet been submitted |
git checkout branchname | Check out or switch branches (note the same command) |
git checkout -b new_branchname | Check out and create a new branch |
git checkout --track origin/dev | Switch to the remote dev branch |
git log | Look at your commit log |
git status | View current status |
git rm [file name] | Delete a file |
Common git usage tutorials
Modify remote warehouse address
Command Line | content |
---|---|
git remote rm origin | Remove remote warehouse |
git remote add origin http://www.xxx.com/aaa/cccc | Add http://www.xxx.com/aaa/cccc as the remote warehouse address |
git push --set-upstream origin master | Set up the upstream source host |
git push --set-upstream origin aaa | Associate the current branch with the remote branch (aaa should be changed to your current branch name) |
git remote -v | View remote warehouse address |
Git global settings
Command Line | content |
---|---|
git config --global user.name “zengshufeng” | Set up an account |
git config --global user.email “xxxxxx” | set password |
Create a new repository
Command Line | content |
---|---|
git clone http://xxxxx/zengshufeng/BeijingAdmin.git | Pull code from remote warehouse to local |
cd BeijingAdmin | Enter the operation of the pulled folder |
touch README.md | Create README.md |
git add README.md | Add README.md to the staging area |
git commit -m “add README” | Add add README information |
git push -u origin master | Push to the server |
Existing folder
Command Line | content |
---|---|
cd existing_folder | Enter the project root directory |
git init | Initialize the local git repository |
git remote add origin http://xxxxx/zengshufeng/BeijingAdmin.git | Create a new remote warehouse, and then add the remote warehouse to the local git project |
git add . | Add all files to the staging area |
git commit -m “Initial commit” | Submit the contents of the staging area to the local library |
git push -u origin master | Push the local library to the remote: At this time, the master branch will be automatically created in the remote and the tracking will be established |
Existing Git repository
Command Line | content |
---|---|
cd existing_repo | Enter the project root directory |
git remote add origin http://xxxxx/zengshufeng/BeijingAdmin.git | Create a new remote warehouse, and then add the remote warehouse to the local git |
git push -u origin --all | Push all local branches to remote |
git push -u origin --tags | Push all local tags to remote |