Git Use Case
Summarize git command
Contents
- Create new file and index
- Create index under current directory
- Commit(local)
- Add and commit
- Delete old commit
- Copy existed git repository
- Sync from remote or others
- Merge
- Tag
- Resolve conflicts
- Update submodule
- Add submodule
- Remove from submodule(deinit)
- Show branch list
- Show Remote branch list
- Create new branch
- Change branch
- Delete local branch
- Delete remote branch
- Delete local tag
- Delete remote tag
- Delete remote origin tag
- Change branch name
- Log
- Show configuration list
- Unset configuration
- Change default git editor
Create new file and index
git add filename
Create index under current directory
git add .
Add means that it creates index on the local repository
Commit(local)
git commit -m "message"
Add and commit
Add and commit at the same time
git commit -a -m "Message"
Delete old commit
Delete previous commit(include remote commit)
Use hard reset
git reset --hard commit_number
You can use HEAD, HEAD~ or other identifiers for commit number
Copy existed git repository
Not ssh
git clone /User/kiririn/Public/project help_project
In case of ssh
git clone ssh://kiririn.com/~kiririn/Public/project.git
In case of https
git clone https://www.atmarkplant.com/project.git
Sync from remote or others
git pull
Merge
(ex)Source is master, Target is develop
Merge develop branch into master
git checkout master # if you aren't master git merge develop # merge develop into master git commit -m "" # commit git push origin # push remote(origin)
Tag
You can add tag to the latest commit
git tag tag_name # create tag git push origin tag_name # push remote if you want
Resolve conflicts
When you execute merge, sometime conflicts, what should we do?
Check conflicts status
git status
Fix <<<<<<< , =======, >>>>>>> parts.
After fixing conflicts(add again)
git add .
git commit
Update submodule
git submodule update --force --init
Add submodule
git submodule add <url>/project.git ./submodules/project
url is your git URL. project is your project name
.gitmodules and config/modules are updated
[submodule "submodules/project"] path = submodules/project url = <url>/project.git
Remove from submodule(deinit)
git submodule deinit path git rm path
In this case, path is submodules/project
Create new branch
git branch newbranchname
newbranchname is new branch name
Change branch
Use checkout
git checkout branchname
branchname is branch name you want to change.
Show branch list
git branch -a
This commands shows both local and remote
Show Remote branch list
git branch -r
Delete local branch
git branch -d branchname
Delete remote branch
git push --delete origin branchname
or
git push origin :branchname
Add : to former of branchname
Delete local tag
tagname is tag name
git tag -d tagname
Delete remote tag
tagname is tag name
git tag --delete tagname
Delete remote origin tag
git tag -d tagname git push origin :tagname
Change branch name
First you need to checkout the branch you want to change name
git branch -m "new_name"
Not needed “, new_name is new branch name
Log
git log
Show configuration list
See all setting of your git
git config --list
If you want to see only localsetting
git config --local --list
If you want to global setting
git config --global --list
Unset configuration
git config --unset key
key is setting name
if you want to unset global setting, you need to add –global
git config --unset --global key
local is same, add –local
Change default git editor
git config --global core.editor emacs
If you want to change nano, use nano.
Reset force one push
git push -f origin HEAD^:maste