{{title}}¶
- Table of contents
- {{title}}
- Useful tools
- Pre-requisites
- Create your ssh key pair
- Create/modify the config file
- Send your authorization request
- Test your configuration
- Customize your local account for your local Git client
- Pushing your repo to a Remote Server
- Delete last commit message
- Undo a commit and redo
- Clone an existing repo
- Update your local repo
- Change remote
- Add remote
- Using branches
- Merge detached HEAD back to origin/master
- Example of git operations on existing code
- Playing with tags
- Access your Git repo from another system
- Access your Git repo in read-only mode from Internet
- Access Git repo with TortoiseGIT
- Exclude files or folder for repo (eg. binary files, test files .. )
- Deleting a git repo
- Using Eclipse - EGit
- Working with submodule
- Links
Useful tools¶
- DiffMerge is an application to visually compare and merge files on Windows, OS X and Linux.
Pre-requisites¶
Linux¶
You need a Git client installed on your local computer. Usually it is already installed as you can verify with the command which git
e.g.:
> which git /usr/bin/git
Windows¶
If you don't already have them, download putty.exe, plink.exe, pageant.exe, and puttygen.exe from the PuTTY web site.
On Windows, you can install a Git Client following, for example, the procedure shown in the first part of An Illustrated Guide to Git on Windows you can find here. THe installation will install:
- Git Bash
- Git GUI
Create your ssh key pair¶
Login into your local computer, and execute the procedure detailed below to generate the ssh keys private and public keys.
Note: no use passphrase
Linux¶
Step 1: generate your keys under $HOME/.ssh
Option a): create your ssh keys in openssh format from scratch
cd $HOME/.sshssh-keygen -t rsa -f <your-surname>
e.g.: trifoglio@localhost:~/.ssh> ssh-keygen -t rsa -f trifoglio Generating public/private rsa key pair. Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in trifoglio. Your public key has been saved in trifoglio.pub. The key fingerprint is: 9a:99:e2:33:b6:f1:46:0d:0c:11:1d:7b:85:ba:78:56 trifoglio@localhost The key's randomart image is: +--[ RSA 2048]----+ | o+.. .. | | . .... | | o... | | +.E | | . =S | | . ==. | | o+= | | .++. | | .o=. | +-----------------+ trifoglio@localhost:~/.ssh> ls config trifoglio trifoglio.pub
Option b): import your ssh keys created in .ppk format (e.g. with puttygen under Windows)
- download and install (as root) Putty for Linux, (e.g. putty-0.63-1.el6.rf.x86_64.rpm)
- convert your .ppk keys into openssh format, e.g.:
cd cd .ssh puttygen trifoglio.ppk -o trifoglio.pub -O public-openssh puttygen trifoglio.ppk -o trifoglio -O private-openssh
Step 2
- Create/modify the ssh config file, with permissions like
-rw-r--r-- 1 trifoglio info 111 Nov 6 2012 config
Windows¶
Step 1: set your HOME environment variable
See here for WIN7) to set it to your home, e.g. add the "HOME" variable to the value:
C:\Users\massimo
Step 2: generate your keys
Under Window you need your ssh key pair as follows:
- private key in both ppk format (named
<your-surname>.ppk
) and openssh format (named<your-surname>
) - public key in
<your-surname>.pub
in openssh format
If you have already these keys go to step 3.
Otherwise to generate new keys:
- Begin by running the puttygen.exe program downloaded earlier. Next, click the Generate button to generate the public-private key pair.
- After processing for a few seconds, the Pubblic key for pasting into OpenSSH authorized_keys file is shown in the upper part of the Puttygen window, as shown below:
- select with the mouse all the text in that window and, with your preferred editor, copy/paste it into the file <your surname>.pub ( Do not click the Save public key button because the saved file is in .ppk format).
- click the Save private key button to save your new private key in .ppk format to the file <your surname>.ppk (without passphrase)
- select Conversions->Import Key tool from the menu bar and load the <your surname>.ppk file
- select Conversions->Export OpenSSH key to create your openssh format private key file (named
<your-surname>
) (without passphrase)
Step 3: put your keys into your HOME
Put both private keys (i.e. <your surname> and <your surname>.ppk) and the public key in the HOME/.ssh folder (which means you must have HOME environment variable defined on Windows as in Step 1).
Step 4:
Add your private key <your surname>.ppk to pageant.exe
You need our private key to be loaded up to use with our public key, so launch pageant.exe. This program will create an icon in your system tray. Double clicking on the icon will open up a window into which the private key <your surname>.ppk) can be added. Once the private key is added, the agent will sit in the background and provide authentication when needed.
Create/modify the config file¶
Linux/Windows¶
In the same .ssh directory create/modify the file config
by adding the following statements.
(Note: also in the Windows case the IdentityFile points to the private key in Open-ssh format)
Host gitbox User gitolite Hostname gitvm.iasfbo.inaf.it Port 22 IdentityFile ~/.ssh/@<your-surname>@
e.g.:
Host gitbox User gitolite Hostname gitvm.iasfbo.inaf.it Port 22 IdentityFile ~/.ssh/trifoglio
Logout from your session and login again (to update you ssh identity).
Send your authorization request¶
Create an e-mail with the following information:
- login name: <your-surname>
- Your e-mail address
- Repository name: <PROJECT-NAME>
e.g.: ASTRI
with in attachment the SSH public key file (i.e. the .pub file created above).
Send this e-mail to redmine-support@iasfbo.inaf.it
Note: once your pubblic SSH key shall be authorized, you shall have access from the system where you generated the ssh key pair and from any other system where you shall copy the ssh key pair and set-up the ssh config file as detailed above.
Test your configuration¶
You will receive an e-mail as soon as the access rights are granted.
Linux¶
You are ready to test this access with the command ssh gitbox info
, which shows you the list of Git repositories that you can access.
In the example below, the authorized user trifoglio
is allowed to:
- create personal repositories under ASTRI/Sandbox/trifoglio/
- read and write on the repositories created under ASTRI/Sandbox/
E.g.:
trifoglio@localhost:~/.ssh> ssh gitbox info hello trifoglio, this is gitolite@gitvm running gitolite3 v3.1-6-g70ad045 on git 1.7.1 R W C ASTRI/Sandbox/CREATOR/[a-zA-Z0-9].* ... R W ASTRI/Sandbox/conforti/tmgenerator1 R W ASTRI/Sandbox/gitolite-trifo-bitonno/prova-repo R W ASTRI/Sandbox/trifoglio/prova-repo ...
Windows¶
Use the "Git Bash" installed above to give the ssh command as in the Linux case.
If ssh daemon asks for a password¶
- Try the following ( see here) using the ssh-agent:
- First add your key to the agent: ssh-add ~/.ssh/$keyfile. - Then verify that the key is loaded successfully: ssh-add -l - Then try to ssh to your remote box. (The agent should do the authentication.) If there really is a problem with your key you should notice once you try to add it.
- Some more hints are given here.
Customize your local account for your local Git client¶
In the Windows use the "Git Bash" installed above to give the ssh commands.
Set the user name and e-mail that Git will apply to your commits. E.g.:
trifoglio@localhost:~/test-repo> git config --global user.name "Massimo Trifoglio" trifoglio@localhost:~/test-repo> git config --global user.email "trifoglio@iasfbo.inaf.it"
On MAC, if you get the error:
dyld: unknown required load command 0x80000022
it should be a version problem of your local git. Some hints on how to solve the problem are available here.
Pushing your repo to a Remote Server¶
Once you've verified in the previous step that you've been authorized to write into a repository on the IASFBO remote Git server, you can push there any of your local Git repo.
Linux¶
To start a fresh project, create the your local root directory and initialize it, and create your files, e.g.:
trifoglio@localhost:~/.ssh> cd trifoglio@localhost:~> mkdir test-repo trifoglio@localhost:~> cd test-repo trifoglio@localhost:~/test-repo> git init Initialized empty Git repository in /home/trifoglio/test-repo/.git/ trifoglio@localhost:~/test-repo> touch READ
If you would transform into a local repo one existing project, just cd
into your project local root directory and just add the required Git stuff, e.g.:
trifoglio@localhost:~> cd test-repo trifoglio@localhost:~/test-repo> git init Initialized empty Git repository in /home/trifoglio/test-repo/.git/ trifoglio@localhost:~/test-repo> git add --all
If you have already a local Git repo, just cd
there.
Before pushing, add the relevant files in the staging are and perform a local commit, e.g.:
trifoglio@localhost:~/test-repo> git add READ trifoglio@localhost:~/test-repo> git commit -m 'initial setup' [master (root-commit) 83c9d34] initial setup 0 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 READ perform a local commit
When you are ready to perform the first push, e.g. for the ASTRI project:
Define an alias
for the remote git repo. E.g. for the Sandbox:
git remote add origin gitbox:<PROJECT-NAME>/Sandbox/<your-surname>/<repo-name>.git
e.g.
trifoglio@localhost:~/test-repo> git remote add origin gitbox:ASTRI/Sandbox/trifoglio/prova-repo.git
or:
git remote add origin gitolite@gitvm.iasfbo.inaf.it:<PROJECT-NAME>/Sandbox/<your-surname>/<repo-name>.git
e.g.
trifoglio@localhost:~/test-repo> git remote add origin gitolite@gitvm.iasfbo.inaf.it:ASTRI/Sandbox/trifoglio/prova-repo.git
Now you can push, e.g.
trifoglio@localhost:~/test-repo> git push origin master Initialized empty Git repository in /dischi/ciws/data0/gitolite/repositories/ASTRI/Sandbox/trifoglio/prova-repo.git/ Counting objects: 3, done. Writing objects: 100% (3/3), 215 bytes, done. Total 3 (delta 0), reused 0 (delta 0) To gitbox:ASTRI/Sandbox/trifoglio/prova-repo.git * [new branch] master -> master trifoglio@localhost:~/test-repo>
NOTE:
The first git push always require to specify the branch you want to push.
git push -u origin master
Then the next push can be done, from the same branch, as you intended:
git push
To add a subdirectory
$ mkdir subdir2 $ cd subdir2 $ git init Initialized empty Git repository in /home/trifoglio/tmp/subdir2/.git/ $ touch AAAREADME $ git add --all $ git commit -m 'initial setup' [master (root-commit) e7e5b78] initial setup 0 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 AAAREADME $ git remote add origin gitbox:ASTRI/Sandbox/trifoglio/subdir2/provasubdir.git $ git push origin master Initialized empty Git repository in /dischi/ciws/data0/gitolite/repositories/ASTRI/Sandbox/trifoglio/subdir2/provasubdir.git/ Counting objects: 3, done. Writing objects: 100% (3/3), 220 bytes, done. Total 3 (delta 0), reused 0 (delta 0) To gitbox:ASTRI/Sandbox/trifoglio/subdir2/provasubdir.git * [new branch] master -> master $
Windows using Git GUI¶
Following this guide create a local Git repository with some code as shown in sections:
- Creating a repository
- Committing
Now it is time to push as follows:
1) run pageant.exe (Putty authentication Agent) and load your private key (e.g. .ssh/username.ppk)
2) Remote → Push will open up the push dialog.
Typing in the commit address for the project and clicking Push will send the changes on their way.
In the example below, on the Git Server the user trifoglio-VAIO has been registred with the pubblic key file trifoglio-VAIO.pub.
Delete last commit message¶
If the commit only exists in your local repository and has not been pushed, you can amend the commit message with the command:
- On the command line, navigate to the repository that contains the commit you want to amend.
- Type git commit --amend and press Enter.
- In your text editor, edit the commit message and save the commit.
Undo a commit and redo¶
$ git commit -m "Something terribly misguided" (1) $ git reset HEAD~ (2) << edit files as necessary >> (3) $ git add ... (4) $ git commit (5)
1) This is what you want to undo
2) This leaves your working tree (the state of your files on disk) unchanged but undoes the commit and leaves the changes you committed unstaged (so they'll appear as "Changes not staged for commit" in git status, and you'll need to add them again before committing). If you only want to add more changes to the previous commit, or change the commit message1, you could use git reset --soft HEAD~ instead, which is like git reset HEAD~ (where HEAD~ is the same as HEAD~1) but leaves your existing changes staged.
3) Make corrections to working tree files.
4) git add anything that you want to include in your new commit.
5) Commit the changes
Clone an existing repo¶
Linux¶
[trifoglio@bitonno git-test]$ git clone gitbox:testing3 Cloning into testing3... remote: Counting objects: 3, done. remote: Total 3 (delta 0), reused 0 (delta 0) Receiving objects: 100% (3/3), done. [trifoglio@bitonno git-test]$ ls testing ls: testing: No such file or directory [trifoglio@bitonno git-test]$ ls testing2 testing3 [trifoglio@bitonno git-test]$ ls testing3 README
Windows with Git Bash¶
1) check that pageant.exe (Putty authentication Agent) is running and has loaded your private key
2) git clone ssh://gitolite@gitvm.iasfbo.inaf.it/repo_name
e.g.:
git clone ssh://gitolite@gitvm.iasfbo.inaf.it/testing3
Update your local repo¶
Linux¶
1) Check the current status of your local repo respect to the remote repo:
git fetch origin
git log origin/master
2) in case you want to update your local repo
$ git pull remote: Counting objects: 3, done. remote: Compressing objects: 100% (2/2), done. remote: Total 2 (delta 0), reused 0 (delta 0) Unpacking objects: 100% (2/2), done. From gitbox:testing3 5e14289..fc49aa5 master -> origin/master Updating 5e14289..fc49aa5 Fast-forward 0 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 README-bis $ ls README README-bis
In case pull
fails, try the command git status to get some hints on how to solve the error.g.:
$ git status $# On branch master $# Your branch is behind 'origin/master' by 3 commits, and can be fast-forwarded. $# $# Changes to be committed: $# (use "git reset HEAD <file>..." to unstage) $# $# modified: gitolite.conf $# new file: ../keydir/cefala.pub $# $# Changes not staged for commit: $# (use "git add <file>..." to update what will be committed) $# (use "git checkout -- <file>..." to discard changes in working directory) $# $# modified: gitolite.conf $#
in this example, the solution is to remove the files from the stage area:
git reset HEAD gitolite.conf git reset HEAD ../keydir/cefala.pub
$ git status
$ # On branch master
$ # Your branch is behind 'origin/master' by 3 commits, and can be fast-forwarded.
$ #
$ # Untracked files:
$ # (use "git add <file>..." to include in what will be committed)
$ #
$ # ../keydir/cefala.pub
$ # nothing added to commit but untracked files present (use "git add" to track)
Another case were pull fails is when you made local modifications and also someone pushed modifications to the remote repo.
git pull Cannot pull with rebase: You have unstaged changes. Please commit or stash them.
This would be if you wanted to keep them.
After pulling, you would then do git stash pop and your changes would be reapplied.
$ git stash Saved working directory and index state WIP on master: 4f94d25 edited -std option HEAD is now at 4f94d25 edited -std option $ git pull remote: Counting objects: 5, done. remote: Compressing objects: 100% (3/3), done. remote: Total 3 (delta 1), reused 0 (delta 0) Unpacking objects: 100% (3/3), done. From .... 4f94d25..e9cef17 master -> origin/master First, rewinding head to replay your work on top of it... Fast-forwarded master to e9cef175d6f04bfcae6c093f153ab7b8d31dbe30. $ git stash pop Auto-merging ....
Windows with Git Bash¶
1) check that pageant.exe (Putty authentication Agent) is running and has loaded your private key
2) execute with Git Bash the same commands of the Linux case above.
Change remote¶
to show the current "remote" definition:
git remote -v
i.e.:
git remote -v
origin gitbox:ASTRI/Sandbox/trifoglio/Test1 (fetch)
origin gitbox:ASTRI/Sandbox/trifoglio/Test1
to change remote:
git remote rm origin
git remote add origin repo_path
After removal you need to push like this:
git push -u origin master
Add remote¶
by adding another remote you can keep synchronized you local repo with different remote repos.
e.g.
in addition to:
git remote add origin new-origin
you define:
git remote add origin2 new-origin2
hence:
git add ....
git commit ....
git push -u origin master
git push -u origin2 master
Using branches¶
- list branches
$ git branch
master (master is the only existing branch)
git branch -f dev
$ git branch
*master
dev
- git checkout dev (merge master into branch)
- git branch (to verify in which branch you are working)
* dev master
- push to the new branch
- git status
On branch dev Your branch is up-to-date with 'origin/dev'. Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git checkout -- <file>..." to discard changes in working directory) modified: CMakeLists.txt modified: procsctmlib/raw/RawFun.cpp modified: procsctmlib/raw/RawFun.hpp no changes added to commit (use "git add" and/or "git commit -a")
- git add -A
- git commit -m "..message..."
[dev 9b4f104] updated for new data set 2017/03/28 with ... 3 files changed, 37 insertions(+), 12 deletions(-)
- git push origin dev
Counting objects: 7, done. Delta compression using up to 4 threads. Compressing objects: 100% (7/7), done. Writing objects: 100% (7/7), 1.17 KiB | 0 bytes/s, done. Total 7 (delta 5), reused 0 (delta 0) To gitvm.iasfbo.inaf.it:/NISP/NI-IWS/ProcScienceTM/ProcessScienceTM_03.git 9a065dd..9b4f104 dev -> dev
- retrieve the dev branch into another computer
git pull origin dev
- merge modifications made in the dev branch into the master branch
git checkout master
git merge dev (local merge)
git push origin master (remote merge)
- merge modification made in the master into the dev branch
git checkout master
git pull origin master
git checkout dev
Merge detached HEAD back to origin/master¶
$git checkout –b temp #makes a new branch from current detached HEAD $git branch –f master temp #update master to point to the new <temp> branch $git branch –d temp #delete the <temp> branch $git push origin master #push the re-established history
More details here.
Example of git operations on existing code¶
- extract source code (e.g.: TASIlib) from a tar file on a local dir TASIlib_sw
- init a git repo in the TASIlib_sw dir and change the status of all files and sub-dirs from untracked to staged.
cd TASIlib_sw; git init; git add -A
- make the staged files and sub-dirs part of the local repo by committing them
git commit -m "Commit TASI version retrieved on 11 Feb 2016"
- push the local repo up to the remote repo
git remote add origin gitbox:NISP/EDEN/TASIlib_sw.git git push -u origin master
- modify the code as needed
- view the commit status
[TASIlib_sw (master)]$ git log
commit 4a005a87394a6e56342b1e4b80e525153cec5686 Author: Massimo Trifoglio <trifoglio@iasfbo.inaf.it> Date: Mon Feb 15 14:13:44 2016 +0100 Commit TASI version retrieved on 11 Feb 2016
- stage and commit the modifications to the local repo
[TASIlib_sw (master)]$ git commit -a -m "Commit modifications to cmake files"
[master 7271253] Commit modifications to cmake files 6 files changed, 14 insertions(+), 3 deletions(-) [TASIlib_sw (master)]$ git log commit 72712532879615ebd5eb609c5464afe4e82ab260 Author: Massimo Trifoglio <trifoglio@iasfbo.inaf.it> Date: Tue Feb 23 11:56:00 2016 +0100 Commit modifications to cmake files commit 4a005a87394a6e56342b1e4b80e525153cec5686 Author: Massimo Trifoglio <trifoglio@iasfbo.inaf.it> Date: Mon Feb 15 14:13:44 2016 +0100 Commit TASI version retrieved on 11 Feb 2016
- Check the commit status
[TASIlib_sw (master)]$ git status
# On branch master # Your branch is ahead of 'origin/master' by 1 commit. # (use "git push" to publish your local commits) # nothing to commit, working directory clean
- tag both commits (on local repo)
[TASIlib_sw (master)]$ git tag -a v1.0 4a005a87394a6e56342b1e4b80e525153cec5686 [TASIlib_sw (master)]$ git tag -a v1.1 72712532879615ebd5eb609c5464afe4e82ab260
- Amending the most recent commit message
git commit --amend
Will open your editor, allowing you to change the commit message of the most recent commit.
Additionally, you can set the commit message directly in the command line with:
git commit --amend -m "New commit message"
Make sure you don't have any working copy changes staged before doing this or they will get committed too. (Unstaged changes will not get committed.)
Changing the message of a commit that you've already pushed to your remote branch
If you've already pushed your commit up to your remote branch, then you'll need to force push the commit with
git push <remote> <branch> --force
- Or
git push <remote> <branch> -f
- Retrieve the code into another working dir from the remote repo
cd tmp
[tmp]$ git clone gitbox:NISP/EDEN/TASIlib_sw.git
Cloning into 'TASIlib_sw'... remote: Counting objects: 128, done. remote: Compressing objects: 100% (102/102), done. remote: Total 128 (delta 28), reused 97 (delta 14) Receiving objects: 100% (128/128), 608.89 KiB | 0 bytes/s, done. Resolving deltas: 100% (28/28), done. [tmp]$ cd TASIlib_sw/
- Checkout v1.0 (Note: no commit will be allowed as it is an old version)
[TASIlib_sw (master)]$ git co v1.0
Note: checking out 'v1.0'. You are in 'detached HEAD' state. You can look around, make experimental changes and commit them, and you can discard any commits you make in this state without impacting any branches by performing another checkout. If you want to create a new branch to retain commits you create, you may do so (now or later) by using -b with the checkout command again. Example: git checkout -b new_branch_name HEAD is now at 4a005a8... Commit TASI version retrieved on 11 Feb 2016
- come back to the brach master
[TASIlib_sw ((v1.0))]$ git co master Previous HEAD position was 4a005a8... Commit TASI version retrieved on 11 Feb 2016 Switched to branch 'master'
Playing with tags¶
Show tags¶
[TASIlib_sw (master)]$ git tag
v1.0
v1.1
[TASIlib_sw (master)]$ git log v1.1
commit 72712532879615ebd5eb609c5464afe4e82ab260 Author: Massimo Trifoglio <trifoglio@iasfbo.inaf.it> Date: Tue Feb 23 11:56:00 2016 +0100 Commit modifications to cmake files commit 4a005a87394a6e56342b1e4b80e525153cec5686 Author: Massimo Trifoglio <trifoglio@iasfbo.inaf.it> Date: Mon Feb 15 14:13:44 2016 +0100 Commit TASI version retrieved on 11 Feb 2016 [TASIlib_sw (master)]$ git log v1.0 commit 4a005a87394a6e56342b1e4b80e525153cec5686 Author: Massimo Trifoglio <trifoglio@iasfbo.inaf.it> Date: Mon Feb 15 14:13:44 2016 +0100 Commit TASI version retrieved on 11 Feb 2016
Push tags to remote repo¶
- push code modifications on remote repo
[TASIlib_sw (master)]$ git push origin master
Counting objects: 31, done. Delta compression using up to 4 threads. Compressing objects: 100% (18/18), done. Writing objects: 100% (18/18), 2.51 KiB | 0 bytes/s, done. Total 18 (delta 13), reused 0 (delta 0) To gitbox:NISP/EDEN/TASIlib_sw.git 4a005a8..7271253 master -> master
- push also tags
[TASIlib_sw (master)]$ git push origin master --tags
Counting objects: 2, done. Delta compression using up to 4 threads. Compressing objects: 100% (2/2), done. Writing objects: 100% (2/2), 294 bytes | 0 bytes/s, done. Total 2 (delta 0), reused 0 (delta 0) To gitbox:NISP/EDEN/TASIlib_sw.git * [new tag] v1.0 -> v1.0 * [new tag] v1.1 -> v1.1
[TASIlib_sw (master)]$ git remote -v
origin gitbox:NISP/EDEN/TASIlib_sw.git (fetch) origin gitbox:NISP/EDEN/TASIlib_sw.git (push) [TASIlib_sw (master)]$
Delete a tag from the remote repo¶
To delete a tag named "1234":
$ git tag -d 1234 $ git push origin :refs/tags/1234
Access your Git repo from another system¶
copy the contents of .ssh folder in the new system:
scp -R .ssh/ <user_of_system>@<new_machine_address>:/home/<user_new_system>/ssh
Your private key is now available also in the new system.
You must check that the in the .ssh
directory the file config
has been set with the correct permission, i.e. user read-write access only. If not, set it:
chmod 600 config
Access your Git repo in read-only mode from Internet¶
By default, anybody may have read-only access from Internet to any repo of the git server@IASFBO using the URL:
git://iasfbo.inaf.it/your-repo-path.git
e.g.:
git clone git://gitvm.iasfbo.inaf.it/ASTRI/Sandbox/tanci/NCTest.git Cloning into NCTest... remote: Counting objects: 61, done. remote: Compressing objects: 100% (42/42), done. remote: Total 61 (delta 15), reused 0 (delta 0) Receiving objects: 100% (61/61), 11.01 KiB, done. Resolving deltas: 100% (15/15), done.
Access Git repo with TortoiseGIT¶
Open TortoiseGit Settings :
Network section > SSH Client input > Browse...
Look up for ssh.exe in msysgit installation directory, e.g. :
C:\Program Files\Git\bin\ssh.exe
Once you changed the ssh client to ssh.exe you can fully take advantage of your ssh config file, e.g.:
In TortoiseGit when adding a remote, or cloning use the following url :
ssh://gitolite:repository_name
e.g.:
ssh://gitolite@gitvm.iasfbo.inaf.it/testing
No need to look for a private key file, openssh will do the identification according to host section of your config file:
Host gitbox
User gitolite
Hostname gitvm.iasfbo.inaf.it
Port 22
IdentityFile ~/.ssh/<your_openssh_private_key>
Exclude files or folder for repo (eg. binary files, test files .. )¶
In git you can select the files or folders to exclude by the git repo.
[conforti@ciwssw01 processorC11]$ cd .git/info/ [conforti@ciwssw01 info]$ vi exclude
For example:
# git ls-files --others --exclude-from=.git/info/exclude # Lines that start with '#' are comments. # For a project mostly in C, the following would be a good set of # exclude patterns (uncomment them if you want to use them): *.[oa] *.bin *.raw *.fits *.lv0 # *~ ~
Now the file with extensione above selected will not add to repo.
If you have already committed temporary files you can delete them with the command:
git rm -r --cached .
Deleting a git repo¶
$ git ls-remote u1:foo/u1
Initialized empty Git repository in /home/g3/repositories/foo/u1.git/
$ ssh u1 D rm foo/u1
'foo/u1' is locked!
$ ssh u1 D unlock foo/u1
'foo/u1' is now unlocked
$ ssh u1 D rm foo/u1
'foo/u1' is now gone!
Using Eclipse - EGit¶
Git@IASFBO can be operated from Eclipse using Egit.
You can refere to the tutorial here with the caveat that, for remote operations, you have to use the ssh key pair instead of "https".
To this purpose, you need (see also here):
- to create and configure the ssh key pair as presented above
- to configure Git to use them, i.e.:
Select: Window -> General -> Network Connections -> SSH2 and set: - SSH2 Home: the directory .ssh containing the ssh key pair (es: /home/trifoglio/.ssh) - Private keys: add your private key using the specific button
- to run Pageant and load your private key
In remote operations specify the variuos fields as shown in the clone example below, where:
- Repository Path: the path of your remote repository path, e.g.
/ASTRI/Sandbox/<your surname>/xxxxx.git
were xxxxxx is the local main dir containing your code, e.g.
camera_sw.git
Working with submodule¶
Add a submodule - example¶
cd "module-path"
git submodule ( to list the current submodules)
bb5aa5c02d71472cdf49f884692af472c389aced Configurator (v1.0.0-3-gbb5aa5c) 54ac64bac80e2aea15ea71338a5e981c62a74b6b ControlPanel (v0.1-26-g54ac64b) c8bd96f1805f856c8adb4248e6b91aee601dc34d DISCoSConf (v0.1-1-gc8bd96f)
git submodule add gitbox:NISP/EDEN/TASIlib_sw.git
- git submodule add – This simply tells Git that we are adding a submodule. This syntax will always remain the same.
- gitbox:NISP/EDEN/TASIlib_sw.git – This is the external repository that is to be added as a submodule. The exact syntax will vary depending on the setup of the Git repository you are connecting to. You need to ensure that you have the ability to clone the given repository.
- the submodule is added to the git module of the current directory.
git submodule
bb5aa5c02d71472cdf49f884692af472c389aced Configurator (v1.0.0-3-gbb5aa5c) 54ac64bac80e2aea15ea71338a5e981c62a74b6b ControlPanel (v0.1-26-g54ac64b) c8bd96f1805f856c8adb4248e6b91aee601dc34d DISCoSConf (v0.1-1-gc8bd96f) f70647ad2ef085f72dc898eb123459937373a79a TASIlib_sw (v1.4)
Delete a submodule¶
Delete the relevant section from the .gitmodules file.
Stage the .gitmodules changes git add .gitmodules
Delete the relevant section from .git/config.
Run git rm --cached path_to_submodule (no trailing slash).
Run rm -rf .git/modules/path_to_submodule
Commit git commit -m "Removed submodule <name>"
Delete the now untracked submodule files
rm -rf path_to_submodule
To retrieve change history of a given file¶
git log --follow -p -- path-to-file
E.g.:
git log --follow -p -- ./RawFun.hpp > pippo.txt
Links¶
- EGit User Guide
- http://wiki.winehq.org/GitWine
- Egit Tutorial
- Git version control with Eclipse (EGit) - Tutorial
- http://wiki.winehq.org/GitWine