git Series --- work projects common git operations

 

0, local git installation

Official website to download


1, git configuration


git config user.name  see the usernames

git config user.email   view mailbox

git config --global user.name <name>   modify the user name

git config --global user.email <email>   modify the mailbox

ssh-keygen -t rsa -C "[email protected] " create [SSH key can fill any value as a note key, such as mailboxes]

ssh -T [email protected] test the SHH key code has been added to the [cloud] gitee.com


2. Create Repository


git init   initializes the local repository to create a .git subdirectory []

git init [project-name]  create a new directory, and initialized git repositories;

git clone <url>   clone a remote repository;


3, modify, and commit


git status   displays the status of the file has been modified [red did not submit to the staging area, on behalf of the green has been submitted to the staging area;]

  git status -s   displays the status of the file in a minimalist way [red M represents a modification did not submit to the staging area, the green M representatives have submitted to the staging area;]

 

git add   to add files from the working directory to the staging area;

  git add -u | --update   only modified files will be added to the staging area (does not include the added file);

  git add.  to submit modified files and newly added files to the staging area (does not include files that have been deleted);

  git add -a  to add local content of all modifications to the staging area (including the newly added and already deleted);

 

git commit   modified staging area committed to the local repository, while generating a commit-id;

  git commit -m <message>  to modify the staging area committed to the local warehouse

  git commit -a -m <message>  to modify the workspace submitted to the local repository [equivalent to  git add + git commit  ]

  git commit -amend  a submission to modify [the code without any changes, modifications submit information]

 

4, branch operation

git branch

  git branch   to list all local branches

  git branch -r   list all remote branches

  git branch -a lists all local and remote branch

  git branch [branch-name]   to create a new branch, still remain in the current branch

  git branch -m <nameA> <nameB  > branch NameA renamed NameB

  git branch -d [branch-name] deleted branches

 

git checkout

  git checkout [branch-name]   switch to the specified branch

  git checkout -b [branch-name]   Creating a new branch, and the branch switch to

  git checkout - switched to a branch

 

Go merge

  git merge [branch-name] Merging branches to the current branch


5, remote operation


git fetch will update all branches retrieved locally on the remote host, and recorded in .git / FETCH_HEAD in;

  git fetch <remote-name> to download a remote repository of all changes;

  git fetch <remote-name> master : test a new test on the local branch, and branch hosts the master download to the local branch test;


git remote

  git remote -v  displays all remote repository

  git remote show <remote-name> display information to a remote repository

  git remote add <remote-name> [url] adding a new remote repository named


git pull

  git pull <remote host name> <remote branch name>: <local branch name>  to retrieve an update the remote branch, and merged with the local branch

  git pull origin dev: master retrieving remote host dev branches merged with the master branch

  git pull origin dev equivalent to the following two commands:

    git fetch origin to get updates on all branches of the remote host

    git merge origin / dev with combined current branch


git push

  git push <remote host name> <local branch name>: <remote branch> upload local branch to branch to a specified designated remote repository

    Remote branch name is omitted, it said it would push the local branch with the presence of "trace relationship" remote branches, both usually of the same name, which does not exist, will be created;

    Omit the local branch name, remove all the remote branch [This is quite empty push a local branch into a remote branch];

  git push origin master to master branch master branch origin push the latter [the host does not exist, will be created]

  git push origin: master delete the master branch origin host; [equivalent to git push origin --delete master ]


6, undo changes


Modify revoke workspace: [withdrawn after the file changes]

  git checkout - file recovery staging area of the specified file to the workspace

  git checkout. restore all files to the staging area of the workspace

 

After git add []: undo changes temporary area

  git reste HEAD <file>

 

Version rollback:

   git reset --hard <commit_id> 


git log to see your history to determine fall back to that version;

git reflog view the command history, determine the version of Back to the Future;

 

 

 

 

Guess you like

Origin www.cnblogs.com/james23dong/p/12375970.html