-
Clone repository
- Upload your public key to Bitbucket/GitHub
- Clone using command:
git clone git@bitbucket.org:<username>/<repo>.git
-
Pull from master branch
- Use command
git pull
- Use command
-
File operations
git add [..] # Add file(s) git commit [..] # Commit file(s) git rm [..] # Remove file(s) git mv [..] # Move file(s)
-
Commit file(s) to local repo:
git commit [..]
-
Push local repo to master branch:
git push origin master
-
Clean untracked files:
git clean -n
-
To add/initialize submodules:
git submodule add [link to repo] [local path] git submodule update --init --recursive [local path]
-
To remove submodules
-
Delete the relevant section from the .gitmodules file. The section would look similar to:
[submodule "vendor"] path = vendor url = git://github.com/some-user/some-repo.git
-
Stage the .gitmodules changes via command line using:
git add .gitmodules
-
Delete the relevant section from
.git/config
, which will look like:[submodule "vendor"] url = git://github.com/some-user/some-repo.git
-
Run
git rm --cached path/to/submodule
-
Run
rm -rf .git/modules/submodule_name
-
Commit the change
-
Delete the now untracked submodule files
rm -rf path/to/submodule
-
-
Reset submodule
git submodule deinit -f . git submodule update --init
-
Update submodule to master branch
cd my_submodule git checkout master git pull commit=`git rev-parse --short HEAD` # save the commit id cd .. git commit my_submodule -m "reference newer version ($commit) of submodule my_submodule" git submodule update --init --recursive my_submodule
-
List all changed files including those in the sumodules
git submodule foreach --recursive git diff --name-status
-
How to find commit ID for submodules, few options:
- Short commit ID:
git rev-parse --short HEAD
- Long commit ID:
git ls-tree master
- Short commit ID:
-
Show all branches, commits that are not remotes:
git log --branches --not --remotes
- To determine which branch am I on:
git status
- List files that differ from master:
git diff --name-only master
- Compare differences between branches:
git diff master..branchname
- List all branches:
git branch -a
- Rename branch, while on branch:
git branch -m new-branch-name
- Checkout local branch
git checkout <name>
- List remote branches:
git branch -r
- List all origins:
git remote -v
- Checkout remote branch
git checkout -b <branch> origin <branch>
- To switch back to master branch:
git checkout master
- Delete branch:
git branch -D [..]
Working on a local branch of a forked repo. Tricky
git checkout master
git pull origin master (pull from remote master)
git checkout my_branch
git pull origin master (pull from local master?)
-
Update branch to master:
git merge master
-
Steps to sync a forked branch: https://help.github.com/articles/syncing-a-fork/
-
Configure a remote that points to the upstream repository in Git: https://help.github.com/articles/configuring-a-remote-for-a-fork/
- List current remotes:
git remote -v
- Specify new remote upstream:
git remote add upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git
- Verify current remotes:
git remote -v
- List current remotes:
-
Merge fork master with upstream master
- Checkout master branch:
git checkout master
- Merge with upstream master
git merge upstream/master
(or git pull upstream master)?
- Checkout master branch:
-
Update local branch with fork master
git checkout devel-branch
git merge master
-
https://www.cheatography.com/oisch/cheat-sheets/hmi-git-gerrit/
- Why refs/for/master?
git push origin HEAD:refs/for/<BRANCH>
This pushes your changes to the staging area. It doesn't actually have a branch called ; it lies to the git client.
-
Checkout: Fetches the latest changes. You should already have this repo downloaded. It does not merge those new changes but makes your working directory reflect them. You can merge them at your leisure later.
-
Pull: Fetches the changes AND merges them into the local branch of the same name.
-
Cherry-pick: Fetches the commit and plays it on top of the current local branch, thus creating an entirely new commit which happens to have same changes as the one it fetched.
- Tips
- Reset local to head
- Cherry pick commits
- Rebase
- Push