Single team Git base operation

Git Teamwork – Chapter 5 notes

Create a Git version management project

  • Initialize the new project
 mkdir learning-git-for-teams
 cd learning-git
 git init
Copy the code
  • Clone an existing project

git clone https://gitlab.com/gitforteams/gitforteams.git

  • It should be used regularlystatusCommand habits are used as frequently as save is used in word processors.

git status

  • Adds all files in the warehouse to the staging area

git add --all

  • Submit all temporary files to the warehouse

git commit -m "Initial import of all project files."

Log output

  • The log command outputs a complete history of the submitted messages in the repository, in reverse chronological order

git log

  • A quick list of recent submissions

git log --oneline

Branch management

  • Git branch –list

  • Git branch –all

  • Git branch –remotes

  • Git fetch gets the updated list and the contents of all remote branches

  • Git checkout –track origin/video-lessons

  • Create a new development branch

 git checkout master
 git branch 1-process_notes
 git checkout 1-process_notes
Copy the code

Recommended one-line

git checkout -b 1-process_notes master
Copy the code

Add changes to the repository

  • Changes in Git must be staged before being saved to the repository

  • Add the selected changed file to your Git repository

git add README.md process-diagram.png

git add branch-naming-rules.png

  • Adds all files in the specified path

git add <*directory_name*>/*

  • Adds all files with a specific extension

git add *.svg

  • Add edited (or modified) files

git add --update

  • To be more extensive, add the –all argument to add all changes to the file. This is a very greedy command! Before using it, you should check the list of files to be added
git status
git add --all
Copy the code
  • Interactively add to your Git repository

git add --patch <filename>

Remove the added file

Git reset removes the added files from the staging area

$ git status
    On branch master
    Changes to be committed:
     (use "git reset HEAD <file>..." to unstage)
           modified:   ch05.asciidoc

$ git reset HEAD ch05.asciidoc
    Unstaged changes after reset:
    M       ch05.asciidoc
Copy the code

Git ignores files

You can view gitignore. IO for the recommended configuration of each project. If you enter the project type, the.gitignore file is automatically generated.

  • Global configuration ignores file rules

$git config --global core.excludesFile ~/.gitignoreCopy the code
  • Ignore file rule for project configuration (recommended)
    • (1) Create a directory named.gitignoreThe file.
    • (2) One file per line for all the files you definitely don’t want Git to add to your repository. You can use the exact
    • File name or wildcard (e.g. *.swp). (3) Run the add and commit commands.gitignoreAdd files to your repository.

Displays individual submission details

Use the show command to display a single committed log message with the text diff $git show fa04c30

commit fa04c309e3bb8de33f77c54c1f6cc46dc520c2ca
Author: emmajane <[email protected]>
Date:   Sat Oct 25 12:44:39 2014 +0100
   Initial import
diff --git a/ch05.asciidoc b/ch05.asciidoc
new file mode 100644
index 0000000..8f82732
--- /dev/null
+++ b/ch05.asciidoc
@@ -0,0 +1,867 @@
+
+=== Verifying Git
+
+Before we dive into using Git, you'll want to check and see which version is installed. For our purposes, Gi
[etc]
Copy the code

Label management

  • Add a new label import for a submission object

$ git tag import *fa04c30*

  • List all labels

$ git tag

  • View tagged submissions

$ git show *import*

Remote Connection Management

  • Lists remote repositories connected to your current repository

    $ git remote --verbose or $ git remote -v

  • Add a new remote warehouse connection

$git remote add

  • Use the push command to upload the branch

$ git push

You will get an error message when there is no upstream branch

fatal: The current branch 1-process_notes has no upstream branch

To push the current branch and set the remote as upstream, use
         git push --set-upstream origin 1-process_notes
Copy the code

Therefore, a default upstream remote connection is usually required

  • Set the upstream branch when uploading the local branchgit push --set-upstream my_gitlab 1-process_notes

A simple set of GitFlow

  • Branch work order and master branch
 git checkout master
 git merge 1-process_notes
Copy the code

If the merge is performed, a submission message may pop up that needs to be edited, usually using the default information

  • And push the merged to the remote branch

$ git push --set-upstream my_gitlab master

  • Delete the local copy of this branch

$ git branch --delete 1-process_notes

  • Delete all remote branches that are no longer needed

$ git push --delete *my_gitlab 1-process_notes*

conclusion

The command use
git clone URL Download a copy of the remote repository
git init Convert the current directory to a new Git repository
git status Get warehouse status report
git add –all Add all modified files and new files to the staging area of the warehouse
git commit -m “message” Submit all temporary files to the warehouse
git log View project History
git log –oneline View the compressed project history
git branch –list Lists all local branches
git branch –all Lists local and remote branches
git branch –remotes List all remote branches
git checkout –track remote_name/branch Create a copy of the remote branch
git checkout BRANCH Switch to another local branch
git checkout -b branch branch_parent Creates a new branch from the specified branch
git add filename(s) Only the specified files are provisionally saved and ready for submission
git add –patch filename Only some files are provisionally saved and ready to be submitted
git reset HEAD filename Removes proposed file changes from staging
git commit –amend Update the previous commit with the current staging changes and provide a new commit message
git show commit Prints the details of a commit
git tag tag commit Label a submission object
git tag List all labels
git show tag Prints the details of all tagged submissions
git remote add remote_name URL git push Create a reference to the remote repository
git remote –verbose Upload the changes on the current branch to the remote repository and list the urls used by the FETCH and push commands in all available remote connections
git push –set-upstream remote_name branch_local branch_remote Push a copy of the local branch to the remote server
git merge branch Merges a commit currently stored in another branch into the current branch
git push –delete remote_name branch_remote Removes the branch with the specified name from the remote server

The following are the best practices listed in this chapter.

  • Always define what you need to do before you start work. This will help you decide on the branch name and which branch you want to start with.
  • As you make changes on your branch, you can add some or all of your changes to the staging area. This can help you ensure that a submission contains only relevant work.
  • Whether you create a new repository locally or clone a repository, you can always create a new project on the code-managed system and then upload your work by adding a new remote to the repository.
  • The cleanup should be done after you have completed each line of work. You can branch the work order into the main branch and then delete the local and remote copies of the branch.