start

Team to improve efficiency it is very important in the development, basic the vast majority of companies now use git for version control, is not just the git version control system, it is also a content management system (CMS), work management system, is mainly introduced the next team in the daily development of conventional git command project work.

We usually use Git or SVN to manage our code in our work, so how to efficiently store and manage our remote warehouse?

Three long term branches

  • Master branch (online)
  • Develop (Daily development branch)
  • Primary branch Test (Pre-issued branch)

Two short term branches

  • Feature branch Feature -branch
  • Hotfix-branch indicates the online patch branch

These two short-term branches, once developed, need to be merged into the master or dev branch, and the original branch can be removed after merging

Branch management

Automatic synchronization of master on branch

git pull --rebase origin master
Copy the code

View the current branch

git branch
Copy the code

Switching warehouse branches

git check out <branch-name>
Copy the code

View all branches, remote and local

git branch -a 
Copy the code

Viewing remote branches

git branch -r
Copy the code

Delete the local branch (note that in the case of the current branch, the branch cannot be deleted)

git branch -D <BranchName>
Copy the code

Deleting a Remote Branch

git push origin --delete wangenbo
Copy the code

Pull the remote branch

Git checkout -b Local branch name x origin/ remote branch name x or git fetch origin remote branch name x: local branch name xCopy the code

Local management

Initialize the warehouse using the command

git init
Copy the code

Add all the files in the folder

git add .
Copy the code

Submit the file to the local repository

Git commit -m "Add your comments, usually some change information"Copy the code

Associate with the remote repository

Git remote add origin git remote add originCopy the code

Get the remote repository to merge with the local synchronization. If the remote repository is empty, this step can be adjusted

git pull --rebase origin master
Copy the code

Push the contents of the local library to the remote

git push -u origin master
Copy the code

Remove local Git Settings when projects do not need Git to manage projects

rm -rf .git
Copy the code

Example Modify the remote warehouse address

git remote set-url origin url
Copy the code

Warehouse management

Look at the warehouse

git remote -v 
Copy the code

Add an upstream repository that will be synchronized to the fork remote

git remote add upstream <url>
Copy the code

Perform synchronization fork

Git fetch upstream // By default, all remote branches are fetched downCopy the code

Synchronize your own remote branches

git pull origin master 
Copy the code

Perform merge upstream

Merge upstream/ Master branch to local master

git merge upstream/master
Copy the code

Code the rollback

We often upload files by mistake and need to roll back the code to the original historical version:

View the commit history from near to far

(The records here are for commits to remote branches, not including local commits without push history)

git log   
Copy the code

Go back to the last version that was just committed

git reset --hard HEAD^
Copy the code

Go back to the fixed historical version

git reset --hard id
Copy the code

The rollback version is forcibly pushed to remote

(Note that you can’t pull down the branch or it will automatically return to the original situation)

git push origin HEAD --force
Copy the code