How to set up git repository to use external sub-module repository

Adding

Go to sub-folder of your git-folder where you want to put new sub-module and execute

$ git submodule add git_repository_url directory_name

Make sure that directory name does not contain dashes.

Updating

Updating sub-modules from command line

$ git submodule foreach git pull

or by TortoiseGit

Updating sub-modules by TortoiseGit
Updating sub-modules by TortoiseGit.
Advertisements

Often used GIT commands

Pushing new branch

$ git push -u origin new_branch

Fetch all remote branches

$ git fetch origin

View branches list

$ git branch -v -a

Fetch remote branch

$ git checkout -b local_branch origin/remote_branch

Create new branch

$ git checkout -b branch_name

Delete local branch

$ git branch -d branch_name

Delete remote tracking branch (local)

$ git branch -rd origin/branch_name

Delete remote branch

$ git push origin --delete branch_name

Revert all

$ git checkout .

Revert single file

$ git checkout file_name

Set up user attributes

$ git config --global user.name "John Doe"
$ git config --global user.email johndoe@example.com

Get origin name

$ git remote show origin

Merge branches locally

  • Commit changes to original branch
  • Switch to new branch and execute
$ git merge original_branch

Copy commit from another branch

$ git cherry-pick commit_sha

Reset changes to commit

$ git reset --hard commit_sha

Create patch from last commit

$ git format-patch -1 HEAD

Create patch from uncommitted changes

$ git diff > file_name

Remove file from repository and save local copy

$ git rm --cached file_name

How to revert merge request in Git

Create a git patch from the changes in the current working directory

How to synchronize GIT fork with main repository

1. Clone the fork

git clone git@github.com:YOUR-USERNAME/YOUR-FORKED-REPO.git

2. Add remote from original repository in your forked repository

cd into/cloned/fork-repo

git remote add upstream 
    git://github.com/ORIGINAL-DEV-USERNAME/REPO-YOU-FORKED-FROM.git
git fetch upstream

3. Update your fork from original repo to keep up with their changes

git pull upstream master

 

Often used GIT commands