Git Workflow Flowchart

The command

  1. Clone: Cloning code from a remote repository to a local repository
  2. Checkout: Checks out a repository branch from the local repository and makes revisions;
  3. Add: Commits the code to the staging area before committing;
  4. Commit: Commit to the local repository. Each historical version of the change is saved in the local repository.
  5. Fetch: Fetch from the remote library to the local warehouse, without any merge action, generally fewer operations;
  6. Pull: From the remote library to the local library, automatically merge, and then put into the workspace, equivalent to fetch+merge;
  7. Push: After the modification is complete, when the code needs to be shared with team members, the code is pushed to a remote repository;

– Set basic information

git config –global user.name “your name”

git config –global user.email “youremail”

– Obtain the local repository

  • Create an empty directory (such as test) anywhere on your computer as our local Git repository.
  • [Go to this directory and right click to open Git bash window]
  • [Run: git init]
  • [If successfully created, you can see the hidden. Git directory under the folder.]

git init

– Basic operation instructions

git add

Work area => Temporary area

Effect: Adds changes to one or more files in the workspace to the staging area

Git add a single filename | wildcards

Add all changes to the staging area: git add.

git commit -m “message”

Staging area => local warehouse

Effect: Submits staging area contents to the current branch of the local repository

Git commit -m

git status

Action: View modified status (staging area, workspace)

git log[option]

Function: View submission records

options

  • –all Displays all branches
  • –pretty=oneline displays the submission information as oneline
  • –abbrev-commit makes the output commitId shorter
  • Graph is shown in the form of a graph

git reset –hard commitID

Function: The version is rolled back and reset to the commitID version

CommitID can be viewed using the git-log or git log commands

– Branch management

git branch

Viewing local branches

Git branch Specifies the branch name

Create a branch

Git Checkout branch name

Switch branch

Git checkout -b

Switch branches. If no branch exists, create a new branch and switch to this branch

Git merge branch name

Merge branches. Commits on one branch can be merged into another branch

Git branch -d Specifies the branch name

When deleting branches, various checks are required

Git branch -d Specifies the branch name

Forcibly delete without checking

– Remote operation

Git remote add

To add a remote repository, initialize the local repository and then connect to the existing remote repository. Remote name, origin by default, depending on remote server Settings, repository path, get this URL from the remote server;

git remote

Viewing the Remote Warehouse

Git push [-f] [–set-upstream] [–set-upstream]

Push to remote repository If the remote branch name is the same as the local branch name, you can write only to the local branch

git push origin master

-f Indicates mandatory overwrite

–set-upstream pushes to the remote and establishes the connection with the remote branch.

eg:git push –set-upstream origin master

If the current branch is already associated with a remote branch, you can omit both the branch name and the remote name.

Git push pushes the master branch to the associated remote branch.

git branch -vv

View remote branches associated with local branches

Git clone

If there is already a remote repository, we can clone directly to the local.

git fetch [remote name] [branch name]

Fetching command is to fetch all updates in the remote repository locally, without merging. If the remote name and branch name are not specified, all branches are fetched.

git pull [remote name] [branch name]

The fetch command pulls changes to the remote repository locally and automatically merges them. This is equivalent to fetch+merge. If the remote name and branch name are not specified, fetch all and update the current branch.