Git case summary for busy people

All cases

Configure git user name mail

Simply download a warehouse

Pull updates from the remote warehouse to the local warehouse (does not affect existing local commits)

Upload local changes to remote warehouse

Upload local changes to remote warehouse and make local remote consistent

Create a new warehouse and initialize it with local code

I don't want to sync some files / folders

Create a temporary branch from the master for modification, and then merge it into the main branch

Delete all warehouse history, keep current file only

Submit information of n times commit before modification

Configure git user name mail

git config --global user.name "Your Name"  
git config --global user.email "email@example.com"

Simply download a warehouse

Most commonly used method

git clone https://github.com/xxx/xxx.git

The project is too large. You don't need history to download it quickly

git clone --depth 1 https://github.com/xxx/xxx.git

Want to quickly download non master branches

git clone --depth 1 https://github.com/xxx/xxx.git
cd xxx
git remote set-branches origin 'remote_branch_name'
git fetch --depth 1 origin remote_branch_name
git checkout remote_branch_name

Pull updates from the remote warehouse to the local warehouse (does not affect existing local commits)

git pull origin master

Upload local changes to remote warehouse

git add .
git commit -m "Submission instructions"
git push origin master

Upload local changes to remote warehouse and make local remote consistent

git add .
git commit -m "Submission instructions"
git pull origin master
git push origin master

Create a new warehouse and initialize it with local code

First, create a new warehouse on GitHub or other git websites, and obtain the new warehouse address, similar to https://github.com/xxx/xxx.git

git init
git add -A
git commit -m "setup code"
git remote add origin https://github.com/xxx/xxx.git
git push -u origin master

I don't want to sync some files / folders

Create a new. gitignore file in the root directory of the warehouse It contains the content to be ignored, and supports files, folders, and wildcards

target/
.idea/
*.log
somefile.txt

Create a temporary branch from the master for modification, and then merge it into the main branch

  1. Create temporary branch
git checkout master
git pull origin master
git checkout -b tmp
git push origin tmp # Also create temporary branches remotely
git branch --set-upstream-to=origin/tmp
git pull origin tmp
  1. Modify the code in the way you like, and submit the code in the process
git add .
git commit -m "Submission instructions"
git push origin tmp
  1. Finally, merge branch tmp to master and delete tmp
git checkout master
git merge tmp
git push origin master
git branch -d tmp
git push origin --delete tmp

Delete all warehouse history, keep current file only

git checkout --orphan lastest # New branch from 0
git add -A # Add all current files to branch
git commit -m "init information"
git branch -D master # Delete master branch
git branch -m master # Rename the current branch to master
git push -f origin master # Force commit to remote

Submit information of n commit before modification

git rebase -i HEAD~n # View the latest n commit submissions here
# Then enter the edit mode, change the pick in the line of commit to be modified to edit, and save to exit
git commit --amend # This will enter the above to modify the corresponding commit information
git rebase --continue # Back to normal

Tags: git github

Posted on Mon, 16 Mar 2020 04:01:22 -0400 by ashida123