git remote add <remote-name> <remote-repo-url>
Add another remote for current git branch and name it with given nameremote-name
git remote rename <original-name> <new-name>
Rename remoteoriginal-name
tonew-name
git config branch.<branch-name>.remote <remote-name>
Set the default remote of branchbranch-name
toremote-name
, this command will generate below segment in.git/config
:
1 2 3 |
|
File .git/config
is used to store branches and remotes information for a git repository.
git push <remote-name> [branch-name]
Push branchbranch-name
(If not specified, default is current branch) to remoteremote-name
.
git branch -D <branch-name>
Remove branchgit branch -m <orginal-name> <new-name>
Rename branchoriginal-name
to given namenew-name
.git checkout -b test origin/test
Git checkout remote branch
git reflog
Reflog is a mechanism to record when the tip of branches are updated. This command is to manage the information recorded in it.应用场景:
- 当前的working directory的git log如下图所示:
- 用户切换到commit 041f088去查看几天之前系统的某个功能,执行:
git reset --hard 041f088
- 当前的working directory的git log如下图所示:
- 如果想切换回最新代码, 却发现已经不知道之前的HEAD的commit hash, 此时就可以使用
git reflog
命令来查看当前分支上的所有操作记录, 从中找到最新代码对应的commit hash: 从git reflog
显示的操作记录来看,我们是从commit 4a56876 执行reset操作的,所以之前的HEAD是 4a56876, 执行git reset --hard 4a56876
就可以切换回之前的代码.
git clean -f
git clean -f -d
Remove untracked file from working directory. If-d
used, will remove untracked directories in addition to untracked files.git add -p
Interactively choose hunks of patch between the index and the work tree and add them to the index. This gives the user a chance to review the difference before adding modified contents to the index.