“Code Tailor “provides technology related information and a series of basic articles for front-end developers. Follow the wechat public account” Rookie of Xiaohe Mountain “to get the latest articles.

Git git git git git git git git git git git git git git git git git git git git git git git

Install Git first

brew install git
Copy the code

Use the git init

Let’s create a new folder on the desktop called gitTest

Then in the terminal command, CD accesses the appropriate folder, and execute the following command to create a new Git repository

git init
Copy the code

This will give you a.git file in your folder

Don’t panic if you can’t see the.git file, just the hidden file is not open

#Open all hidden files
defaults write com.apple.finder AppleShowAllFiles -bool true

#You also need to close all Finder and reopen it to work
killall Finder
Copy the code

Git. Git. Git. Git. Git

Git Clone

Execute the following command to clone a remote repository

git clone https://github.com/Huzq-Strive/git-application-docs.git
Copy the code

This is a screenshot of the return when the clone was successful

After Clone, remote repository contents are added to the file

Use git add

First CD access to your clone file

Add your own folders and files to it

The file is then added to the staging area using the add command

# cdInto the file
cd git-application-docs

#Add to staging area
git add myFirstGit/firstTryGit.md

#You can force add if the file is ignored
git add -f myFirstGit/firstTryGit.md
Copy the code

I have an add state here

Git Commit usage

Git commit the git commit command is used to commit locally and record your changes.

#Commit your file for the first time
git commit -m "feat: first add file"
#The paper was revised the second time
git commit -m "fix:second try"
Copy the code

Now let’s modify the contents of the file and commit the second time

Use of Git push

After commit, it is push, committing our local changes to the remote repository

#Upload files to the remote repository
git push
Copy the code

The result of a successful push is as follows:

If the previous code was not cloned, then you need to link the repository before you can push it

#Link to the warehouse
git remote add origin https://github.com/rookies-of-XHS/git-application-docs.git
Copy the code

Branch management

  • Create and check out a name namedbranch_tryThe branch of
git checkout -b branch_try
Copy the code

  • Cut back to the main branch
#Cut back to main branch
git checkout main
Copy the code

  • Delete the branch
#Deleting a New branch
git branch -d branch_try
Copy the code

  • pushLocally created branches to remote repositories.
git push https://github.com/Huzq-Strive/git-application-docs.git branch_try
Copy the code

At this point, let’s take a look at the far side of the warehouse and have an extra branch

The use of the pull

In development we often have multiple people doing things and there’s a push and you have to pull it down

#Drop down the modification
git pull
Copy the code

In order to demonstrate the pull operation, we rebuilt a local warehouse to show two people operating at the same time. We skipped the steps of building the warehouse, and directly modified the content, and then pushed it to the warehouse. After that, you can use the pull command from the original file.

Switch to the original folder directory and use pull

If you want to merge your branch into the main branch, use the following command

#Execute under the main branch
git merge branch_try
Copy the code

That’s what’s added to the new branch


This is the result of the merge, with an extra push

And then we push to the far end

At this point, you’ll notice that the branch_try branch is also present on the main branch

Conflict presentation and resolution

Not every merge will be problem-free, but there will be conflicts that conflicts conflicts when you need to resolve them, modify the file to merge those conflicts manually, and then mark the conflict as resolved by executing the following command.

Now let’s demonstrate a conflict

This is the change made under the second file.

Then add & Commit & Push.

Git add myFirstGit/firstTryGit md git commit -m "resove conflicts" git push # to the far endCopy the code

This is the change under the first file.

Both have been modified in the same file. Execute the add & ommmit commands.

Git add myFirstGit/firstTryGit md git commit -m "begin" # side must commit first before they can pullCopy the code

So let’s do pull here.

Git pull #Copy the code

You’ll see that there’s a conflict here, fix conflicts and then commit the result, and you need to resolve the conflict and commit it.

Here you find some strange things, delete them all and save the file.

On the command line, add & commit will push to the remote end.

Git add myFirstGit/firstTryGit md git commit -m "resolve conflicts" git push # to this step is completedCopy the code

Submit a view of the record

  • usegit logCommand to query the history of the submission record, which can be seen to be submittedID
git log
Copy the code

  • Using the tag, create a file named1.0.1The label of the
Git tag 2 eda8fcac6 1.0.1Copy the code

  • Just look at one person’s submission record
Git log --author= HZQ #Copy the code

  • Compress the submission into one line for viewing
git log --pretty=oneline
Copy the code

  • See which files have changed
git log --name-status
Copy the code

That’s all for todaygitAll the actual combat content, thank you for your support to the author! Your attention and praise will be the strongest motivation for us to move forward! Thank you.