Git
Lexical
Need more explainations and more lexic
- Working dir
- Cache, Stage and Index are synonyms. Some command still use –cache but most use –index
- HEAD
–patch See that important [kaar] from IRC
git reset -p
Configuration
git config --global user.email "yourEmail" #your email at Bitbucket
git config --global user.name "yourName" #your name at Bitbucket
Cloning
Fetching
Fetch from remote to HEAD.
Pulling
Fetch and merge from remote repository
Pushing
Need information!
Stagging
! Stagging is global. Not branch specific.
Add all unstaged files
git add .
Add specific file
git add file [file]
Committing
A good question to ask before naming a commit “If I applied, this commit will …”
Commit all staged files
git commit -a[m]
Fixing commit
See Stashing
Change last commit
git commit --amend
! Don’t amend your last commit if you’ve already pushed it.
Reorder commits
Rebase interactively and change or remove commits.
Branching
Creating a new branch
git checkout -b [branch-name]
Listing all branch
git branch
Change branch
git switch branch-name
Rename branch
If you want to rename a branch while pointed to any branch, do:
git branch -m <oldname> <newname>
If you want to rename the current branch, you can do:
git branch -m <newname>
Pushing a branch
Push -u create upstream
git push -u <remote> <branch>
Delete branch
Need formating and complement of informations
git branch -d <local-branch>
git branch -D <local-branch>
git push origin --delete <remote-branch-name>
Rebase
git rebase master
Merging
git merge --squash
Reset
Squash the last 3 commits
git reset --soft HEAD~3 && git commit
git reset -p
Squashing
Squashing commit from HEAD to the desired commit.
git rebase -i HEAD~5
Edit choose an operation pick, squash, fixup
Rebasing
Versioning
Stashing
Show
git show
git show is HEAD~
Diff
Use diff to see changes between branches
git diff [--cached]
Log
Remote
git remote add [name] [remote_name]
git push -u origin master
Stashing
Stash is global not branch specific. Stash is a stack.
git stash list git stash show -p 1
Submodules
git submodule add ssh://uri
Track HEAD
git submodule add -b <branch> <repository> [<path>]
git submodule init
git submodule update
it submodule update --init
git submodule update --init --recursive`
Git 1.8.2 features a new option, –remote, that will enable exactly this behavior. Running
git submodule update --remote --merge
Remove a submodule
Delete the relevant section from the .gitmodules
file.
Stage the .gitmodules changes:
git add .gitmodules
Delete the relevant section from .git/config.
Remove the submodule files from the working tree and index:
git rm --cached path_to_submodule (no trailing slash).
Remove the submodule’s .git directory:
rm -rf .git/modules/path_to_submodule
Commit the changes:
git commit -m "Removed submodule <name>"
Delete the now untracked submodule files:
rm -rf path_to_submodule