- Create a new EMPTY repository in GitLab. (Note: You MUST uncheck "Initialize repository with README")
- Clone from the source remote repository (from e.g. BitBucket, Github):
git clone --mirror git@bitbucket.org:path/to/REPO.git
- Push the local repository to GitLab:
cd REPO.git git push --mirror git@gitlab.com:path/to/REPO.git
Search This Blog
Showing posts with label git. Show all posts
Showing posts with label git. Show all posts
Migrate git repository to GitLab using the command line
Git: disable autocrlf end-of-line conversion
When adding files to git,
You can turn off the autocrlf to fix this:
git add --all, you may get the error:
fatal: CRLF would be replaced by LF in ... ...
You can turn off the autocrlf to fix this:
git config --global core.autocrlf false
see also
Git end-of-line conversion settings
Enable end-of-line conversion
git config --global core.autocrlf input
- Make sure your IDE (Text) Editors are unix/dos EOL aware.
- Global git config:
git config --global core.autocrlf input git config --global core.safecrlf true
- Create .gitattributes file at the root the git repository, and add configuration like below:
* text=auto *.java text *.xml text *.sh text eol=lf *.cmd text eol=crlf *.bat text eol=crlf *.jpg -text *.png -text *.gif -text
- Normalise the EOL for all the files in the repository:
git add --renormalize .
git status # Show files that will be normalized
git commit -m "Introduce end-of-line normalization"
Disable end-of-line conversion
git config --global core.autocrlf false
See also
Configure Git-Bash for Windows Terminal
- Open Settings tab with
Ctrl+,, the click Gear icon to Open settings.json file - Add/Edit Git Bash profile:
{ "guid": "{2ece5bfe-50ed-5f3a-ab87-5cd4baafed2b}", "hidden": false, "name": "Git Bash", "source": "Git", "fontFace" : "Consolas", "fontSize" : 11, "startingDirectory" : "%USERPROFILE%", "acrylicOpacity" : 0.75, "closeOnExit" : true, "colorScheme" : "Campbell", "cursorColor" : "#FFFFFF", "cursorShape" : "bar", "historySize" : 9001, "padding" : "0, 0, 0, 0", "snapOnInput" : true, "useAcrylic" : true }
see also
git not working after Mac OS upgrade
The problem: after upgrade to Catalina, got the error below when executing git command:
To fix it:
$ git push xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
To fix it:
xcode-select --install
SSH access to Github from multiple accounts
- Generate SSH Keys:
ssh-keygen -t rsa -b 4096 -C "email@personal.com" -f ~/.ssh/id_rsa_personal ssh-keygen -t rsa -b 4096 -C "email@work.com" -f ~/.ssh/id_rsa_work
The two commands above generate two key pairs: id_rsa_personal/id_rsa_personal.pub, id_rsa_work/id_rsa_work.pub. - Add SSH Keys to your github accounts.
- Add id_rsa_personal.pub to your personal github account:
- Login to your github
- Go to Settings -> Add SSH Keys
- Copy of the content of id_rsa_personal.pub to the key field
- Click Add Key
- Add id_rsa_work.pub to your github account for work:
- Login to your github
- Go to Settings -> Add SSH Keys
- Copy of the content of id_rsa_work.pub to the key field
- Click Add Key
- Create a file: ~/.ssh/config and add:
Host personal HostName github.com User git IdentityFile ~/.ssh/id_rsa_personal Host work HostName github.com User git IdentityFile ~/.ssh/id_rsa_work
ssh-add -D ssh-add id_rsa_personal ssh-add id_rsa_work
ssh -T personal Hi githubPersonal! You've successfully authenticated, but GitHub does not provide shell access. $ ssh -T work Hi githubWork! You've successfully authenticated, but GitHub does not provide shell access.
Github: Use Access Token to authenticate over HTTPS
- Login to Github
- If you have not enabled Two-factor authentication, you need to enable it:
- Go to "Settings" -> "Security"
- Generate Personal Access Tokens:
- Go to "Settings" -> "Personal Access Tokens"
- Click "Generate new token" at the top right corner.
- Remember/Copy the token.
- Insert the token to your repository url:
https://<token>@github.com/owner/repo.git
- Now you can push to the repository without typing username & password.
Github: fork a repository and sync the fork
- Fork a repository
- Clone the repository:
git clone https://github.com/ORIGINAL_OWNER/ORIGINAL_REPO.git
- Add the original repository as upstream:
git remote add upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPO.git
- Check the status:
git remote -v
You will see:# origin https://github.com/YOUR_USERNAME/YOUR_FORK.git (fetch) # origin https://github.com/YOUR_USERNAME/YOUR_FORK.git (push) # upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPO.git (fetch) # upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPO.git (push)
- Clone the repository:
- Sync the fork with upstream(original):
- Fetch the branches and their respective commits from the upstream repository:
git fetch upstream
- Check out your fork's local master branch:
git checkout master
- Merge the changes from upstream/master into your local master branch. This brings your fork's master branch into sync with the upstream repository, without losing your local changes.
git merge upstream/master
- Push local repository:
git push --tags
- Fetch the branches and their respective commits from the upstream repository:
git: ignore .DS_Store files globally
git config --global core.excludesfile ~/.gitignore
echo ".DS_Store" >> ~/.gitignore
git: revert back to a specific version
- Command 1: Revert back to previous version(Note: substitute to your commit hash.):
git reset --hard 76f134a2692c9472af3227d2f9fdb50548de6c0c git clean -f # clean up local repository git push -f # push back to central repository
- Command 2: The following command reverts everything from the HEAD back to the commit hash:
git revert --no-commit 76f134a2692c9472af3227d2f9fdb50548de6c0c..HEAD
see also
git: list all the files for a particular commit
Use one of the commands below:
git show --name-only 76f134a2692c9472af3227d2f9fdb50548de6c0c
git diff-tree --no-commit-id --name-only -r 76f134a2692c9472af3227d2f9fdb50548de6c0c
ggit show --pretty="format:" --name-only 76f134a2692c9472af3227d2f9fdb50548de6c0c
Mac OS X: install git without xcode
git is included in xcode. but if you just want git, you do not have to install the xcode. You can download and install git for mac.
- Download from http://git-scm.com/download/mac
- Mount the .dmg file and install the .pkg package inside the image.
- After installation you need to prepend /usr/local/git/bin to /etc/paths file and remove /etc/paths.d/git:
sudo sed -i -e '1s/^/\/usr\/local\/git\/bin\'$'\n/g' /etc/paths; rm /etc/paths.d/git
- Set PATH environment variables for non-terminal applications:
/usr/local/git/bin/setup\ git\ PATH\ for\ non-terminal\ programs.sh
Remove file completely from git repository
To remove file dir/secret.txt:
git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch dir/secret.txt' --prune-empty --tag-name-filter cat -- --all
See also
git: discard local changes
- To discard all local uncommitted changes:
git reset --hard
which is equivalent to:git reset --hard HEAD
- To discard the latest local commit(move HEAD back by one commit):
git reset --hard HEAD^
or move HEAD by 3 commits:git reset --hard HEAD~3
GIT: list tags in chronological order
git log --date-order --graph --simplify-by-decoration --pretty=format:'%ai %h %d'
git-log
git: count total number of lines
- Method 1:
git ls-files | xargs wc -l
or count only .java files:
git ls-files | grep '.java$' | xargs wc -l
- Method 2:
git diff --stat $(git hash-object -t tree /dev/null)
Subscribe to:
Posts (Atom)
