how can I connect to gitlab project of groups from shell - gitlab

I want to pull a commit from a gitlab project of group (notice: I am a member of the group) I don't know how to connect to the repository from my gitlab a count. I install the git in my ubuntu, configure then add the ssh pb key to gitlab. I spend hours to know how to pull a commit but I don't get the idea. any help ...

Copy the clone ssh link by clicking on the blue “clone” button in Gitlab:
Make sure to copy the link under the label of “Clone with SSH”.
In a bash terminal you would execute the following based on what you copied:
git clone <your-gitlab-user-name>#gitlab.com:name-of-group/project-name
Next you would checkout the branch/commit that you are interested in:
cd project-name
git fetch origin
git checkout <branch-name>
Depending on your ssh setup on your Ubuntu machine, you may need to add your private key to your ssh-agent before running the git clone command.
In case you run into issues related to this, try the following commands:
eval $(ssh-agent -s)
ssh-add /path/to/private/key # Normally in ~/.ssh/ dir
git clone <your-gitlab-user-name>#gitlab.com:name-of-group/project-name

Related

How to git push to two repositories while git pull from one repository

I'm working on linux server (non-desktop) and I have two repositories. One is for development (github), the other is a local repository of my lab (gitlab).
What I need is to keep the two repositories always exactly the same, and I can push and pull on my dev repository, whereas only push on my local repository so that my colleagues can git pull from my lab repository. My lab-repository is used only for sharing my project with my colleagues: I do nothing but git push and they do nothing but git pull. That's all.
Well, you may ask why don't use the dev repository. That's because they have no right to connect to the Internet.
I don't like to execute many commands for each action. For example, for now I have to execute the commands below to git push to the two repositories:
cd devRepo
# coding here
# git add & git commit & git push here
cd ../myLabRepo
cp -r ../devRepo/* ./
# git add & git commit & git push here
This is kind of boring. Ofc, I know I can use bash script but I'm wondering if there are some specialized tool to do so or maybe Git has the capacity to do so.
You can specify more than one push location for the same remote.
git remote set-url --add --push <remote name> <push url>
Check this with git remote -v
You should see the original push and fetch URLs, along with the extra push URL you just added.
You can add the whole stuff that you have into a bash script and run that. Otherwise, you can add a remote to your first repository and do a push there as well, instead of copying your whole project.
git add & git commit & git pull origin master & git push origin master & git push local master

Mercurial like method for creating git remote repository

When I was using Mercurial, creating a remote repository is one command line:
hg clone local remote
Where remote is something accessible via ssh. For instance:
hg clone /path/to/local/repo.hg ssh://host.name/path/to/new/clone.hg
I don't know if it is a functionality in Mercurial or we have installed something to make that possible.
Is there any way to do that with git? Or install something that will allow me to do the same like with Mercurial?
NOTE
My question is not 'How to clone a remote repository?'
No, you can't do that with a single command, and you can't do that using Git alone either.
You roll something like this:
Initialize a repository on the server:
ssh user#server git init --bare /path/to/the/new/repo
Push your local repository there:
git push --all --tags ssh://user#server/path/to/the/new/repo
If you intend to work with that new remote repository (push/fetch) afterwards, it makes sense to add it as a named remote, so your step #2 becomes:
git remote add foo ssh://user#server/path/to/the/new/repo
git push --all --tags foo

How do I clone a git repository located on my Mac connected to the internet?

I have an up-to-date git repo that I started on my MacBook. The project that I am working on is required to work on my university's Linux workstations that I can login to remotely via SSH. I've cded to the directory that I want to clone to on the workstation. I just have no idea how to get the SSH address for the repo on my MacBook when its connected to the internet. Also, how would this stay consistent considering I get a different IP every time I reconnect or go somewhere? Is what I'm doing even possible or a good idea?
One simple solution is to create an empty repository using a free github.com or bitbucket.org account. Using github for this example, you would then have a URL for the repo such as:
https://github.com/username/repo-name.git
Then, simply push the contents of your local repo up to the newly created online repo like so:
$ git remote add origin https://github.com/<username>/repo-name.git
$ git add --all
$ git commit -m 'initial commit'
$ git push -u origin master

Added BitBucket repo as remote on GitHub

I've just installed git on Ubuntu, now I want to work on my repo in BitBucket. I'm a little confused on how to do so. I can't do the following:
git remote add BitBucketRepo git#bitbucket.org:dir/file.git
As it returns the following error:
fatal: Not a git repository (or any of the parent directories): .git
It clearly is pointing to a git repo, so why is it lying to me?
Also, it is worth noting I am using SSH and I have successfully paired my GitHub account to my computer.
You need to run this command from a local git repository (a directory in which you have run git init or git clone) - otherwise git remote doesn't know which local repo you want to add the remote for.
It should be as simple as cd my-local-dir, where my-local-dir is the directory containing your local (cloned) git repository.
If you don't yet have the repo available locally:
git clone git#github.com:...etc... my-local-dir
cd my-local-dir
git remote add ButbucketRepo git#bitbucket.org...
git push -u ButbucketRepo master
This will clone your code from Github into the my-local-dir directory, add your BitBucket repo as a remote repository, push your code up to Bitbucket and set the local master branch to track the BitBucket remote's master branch.
Tracking means that commands that involve a remote like git push will automatically use the BitBucket remote's master branch. If you don't want that behaviour, skip the -u option.

Git - Syncing a Github repo with a local one?

First off, forgive me if this is a duplicate question. I don't know anything but the basic terminology, and it's difficult to find an answer just using laymen's terms.
I made a project, and I made a repository on Github. I've been able to work with that and upload stuff to it for some time, on Windows. The Github Windows application is nice, but I wish there was a GUI for the Linux git.
I want to be able to download the source for this project, and be able to edit it on my Linux machine, and be able to do git commit -m 'durrhurr' and have it upload it to the master repository.
Forgive me if you've already done most of this:
The first step is to set up your ssh keys if you are trying to go through ssh, if you are going through https you can skip this step. Detailed instructions are provided at https://help.github.com/articles/generating-ssh-keys
The next step is to make a local clone of the repository. Using the command line it will be git clone <url> The url you should be able to find on your github page.
After that you should be able to commit and push over the command line using git commit -am "commit message" and git push
You can use SmartGit for a GUI for git on Linux: http://www.syntevo.com/smartgit/index.html
But learning git first on the command line is generally a good idea:
Below are some basic examples assuming you are only working from the master branch:
Example for starting a local repo based on what you have from github:
git clone https://github.com/sampson-chen/sack.git
To see the status of the repo, do:
git status
Example for syncing your local repo to more recent changes on github:
git pull
Example for adding new or modified files to a "stage" for commit
git add /path/file1 /path/file2
Think of the stage as the files that you explicitly tell git to keep track of for revision control. git will see the all the files in the repo (and changes to tracked files), but it will only do work on the files that you add to a stage to be committed.
Example for committing the files in your "stage"
git commit
Example for pushing your local repo (whatever you have committed to your local repo) to github
git push
What you need to do is clone your git repository. From terminal cd to the directory you want the project in and do
git clone https://github.com/[username]/[repository].git
Remember not to use sudo as you will mess up the remote permissions.
You then need to commit any changes locally, i.e your git commit -m and then you can do.
git push
This will update the remote repository.
Lastly if you need to update your local project cd to the required directory and then:
git pull
To start working on the project in linux, clone the repo to linux machine. Add the ssh public key to github. Add your username and email to git-config.
For GUI you can use gitg.
PS : Get used to git cli, It is worth to spend time on it.

Resources