[git] Git in Practice

时间:2023-03-09 16:04:56
[git] Git in Practice

Work flow with git and github

[git] Git in Practice

Work with Remotes

Check the current status

git status

Check the latest source on remote branch

git fetch
git status
git log <remote>/<branch> --not <current_branch>
git merge <remote>/<branch>

Add an remote Repo

git remote add <shortname> <url>

Check the remote

git remote -v        // check all remote
git remote show <remote> // show the detail status of an remote

Rename an rename

git remote rename <origin> <destination>

Remove the upstream for the current branch

git branch --unset-upstream

Change the remote that <branchA> is trancing

git branch <branchA> -u <new_remote>/<branch>

Push the current branch as an new branch to remote

git push <remote> <branch>

Push changes to another remote branch

git push <new_remote>/<branch>

Work with Branches

Check branches

git branch // check local branches
git branch --all // check local and remote branches

Create a new branch

git branch branchA    // create a new branch based on the current branch
git branch branchB <remote>/<branch> // create a new branch that traces <remote>/<branch>

Switch branch

git checkout branchB    // change the current branch to branchB

Check the mapping between local branch and remote branch

git branch -vv

Rename an branch

git branch -m <oldname> <newname>

Others Common Commands

Show the content of an commit

git show <commit-id>
git show <commit-id> --name-only

Check differences according log

git log branchA --not branchB
git log branchA --not branchB --name-only

Obtain the latest source under version control

git checkout <file-name>    // checkout the latest file under version control, and discard local changes
git checkout <branchA> // switch the current branch to branchA

Commit changes

git commit -m '' .     // submit all tranced files under the current folder, no matter if they are git-added

Reference:

git, git-scm