Connect to github server - github

I have the ip, useename and password of the github server, which uses gitlab, and I need to connect to it and manage files. What should I do?

I'm assuming you're asking how to manage/change files within a git repository. If you're asking something else, I've missed the point, apologies.
Firstly you will need 'git' on your local machine - install it with your package manager or download and install it from the git website.
Once git is installed you can clone a repository (which contains a set of files, and ends in .git) using the git clone command. Run git clone --help for more information on this, but if you already know the address of your git server and the path to the repository, it will look something like as follows:
git clone https://git-server.url/path/to/repo.git
Note that the URL you should use will depend on the configured transport protocol (git, ssh, http[s]) of your git server.
Next, you should makes some local configurations, for example, from a terminal:
git config user.name "your_username"
git config user.email "someone#example.com"
You can add --global to both of these command if you want these changes to persist outside of the current git repo.
Having a cloned repository automatically checks out an initial 'branch' on which you can make changes to files within your repository. See the git docs for a detailed explanation of a branch.
Files can be added, removed or renamed/moved using git add, git rm or git mv respectively.
Finally, you must commit your changes and push them
git commit -m "A message describing your changes"
git remote will confirm the name of the default remote (repo location). In this case, it is assumed to be origin. You can then push your changes to an existing branch (viewed using git branch -r), assumed to be master below:
git push origin master
Here you would be merging your master branch with the remote one. Clearly your permissions/project conventions will dictate what you can/should do to this repo.

Related

Does GitHub use bare repositories under the hood?

Recently, I discovered that git could be initialized with a --bare flag (e.g. git init --bare). It creates a local repository without a working tree (workspace). As far as I understand, such repositories can be used as a remote from which you can clone, pull and push.
Do GitHub and similar services use "bare repositories" under the hood?
I'm wondering because whenever I create a local repo and push it to a remote service (like GitHub, GitLab, Bitbucket, etc.), I don't create the bare repo myself and I'm not sure if it was created at all (implicitly by GitHub). If it wasn't created, then what is tracking the files/history?
tl;dr
Locally, I can do something like this
-- Step 1. Create a local bare repository
$ mkdir bare-repo/
$ cd bare-repo/
$ git init --bare
-- Step 2. Clone a non-bare repo and push changes
$ mkdir non-bare-repo-1
$ cd non-bare-repo-1
$ git clone ../bare-repo .
$ touch file.txt
$ git add .
$ git commit -m "Add file.txt"
$ git push (it pushes changes to the local remote a.k.a. non-bare/)
And I can create another folder and another and all of them will refer to a single (local) bare-repo/ which tracks changes of all cloned repositories.
I wonder if GitHub uses this approach under the hood, or if the bare repositories are used for something else...
Answering my own question
Do GitHub and similar services use "bare repositories" under the hood?
Yes
It looks like bare git repositories were designed to be used as remote instances and GitHub has to use them to get it to work.
P.S.
Related answer by #VonC
It seems that GitHub repository can work as working repository and bare repository at the same time, does that mean GitHub repository is developed from git bare repository
No, Git repos on GitHub are bare, like any remote repo to which you want to push.
Related answer by #duncan
Short answer
A bare repository is a git repository without a working copy, therefore the content of .git is top-level for that directory.
Use a non-bare repository to work locally and a bare repository as a central server/hub to share your changes with other people. For example, when you create a repository on github.com, it is created as a bare repository.
So, in your computer:
git init
touch README
git add README
git commit -m "initial commit"
on the server:
cd /srv/git/project
git init --bare
Then on the client, you push:
git push username#server:/srv/git/project master
...
I believe so. You can in fact create a GitHub repo and deselect all the auto created files (e.g. README.md, LICENSE). You're provided a list of instructions to init, commit and push the repo.

In Eclipse java project, change git repository from an old one to a new one

I have a project in Eclipse that is associated with an old repository in Gitlab. The branch being used is called Test.
I created a new repository in Gitlab (and it only has the README.md file in it). It only has one branch: master.
I need to change the Eclipse project so that it no longer refers to the old repository (and old branch) but instead - refers to the new repository (with he master branch).
How can this be done?
TIA
Update
#Rizwan - thanks for the info. I did the following:
cd to the directory with the code
#initialize the repository
git init
#add reference to the repository I needed
git remote add origin "git#myrepo.com:WORK/<my-repository>.git"
#got what was currently in the repository
git pull origin master
#added code (not in the repository)
git add -A
#commit the code
git commit -m "first commit with code"
#sent it up
git push origin master
There was another message I used as a base (but I cant find it now)
TIA
We can directly perform this operation in Eclipse itself.
Goto - CurrentProject(Right Click) -> Team -> Remote -> Configure push to upstream -> Change(URI)
This might help
Locate your project on your local computer. You can do this by running:
cd /path/to/repo
Then check and confirm a list of all of your existing remotes. To do this run this command:
git remote -v
Change the URL of the remote with the git remote set-url command:
git remote set-url origin gitlab#gitlab.mydomain:root/testproject.git
Check back with the step 2 whether your repo has changed
Refresh/Clean Build your Eclipse project

C9 created workspace before repository

I made the mistake of creating a workspace before a repository on C9.io.
As a result I do not have version control. Naturally, I want to use Git for my project before make any more changes. Everything I have tried has failed. I would rather not have to copy all the code I've made into a new work space with an already set up repository. So if anyone has any suggestions or answers to this problem, via Command line, GUI or anything else that would be wonderful.
cloud9 doesn't do any special magic when cloning from a git repository, and you can add a remote the standard way you would do locally:
git init initialize a git repository in the current folder
git add -a add everything (or what you want)
git commit -m "initial commit" commit
git remote add origin git#github.com:<me>/<repo>.git add your repo
git push origin HEAD:master push HEAD to master branch in the remote you just added

Exporting a local EGit repo to local GitStack repo

I've set up GitStack on my computer in order to be able to make builds of my application on various machines. My Eclipse project has a local git repo but I can't figure out how to connect the two.
The Team > Remote > Push and Team > Push to Upstream are unavailable (grey).
I've configured the following things and read this tutorial:
Git user name and email in Eclipse.
I've added a user and a repo in Gitstack.
I've also tried to click on my local git repo and do Paste Repository Path or URI and I manage to connect to my GitStack repo on localhost though its obviously empty. I suppose this is what I have to do on other machines to sync stuff?
How do I connect the two?
Here are my command line attempts (note: im using cygwin):
[~/eclipse/JfxMCApp]> git.exe remote add jfxmcapp.gitstack.local http://localhost/JfxMCApp.git
[~/eclipse/JfxMCApp]> git.exe remote -v
jfxmcapp.gitstack.local http://localhost/JfxMCApp.git (fetch)
jfxmcapp.gitstack.local http://localhost/JfxMCApp.git (push)
[~/eclipse/JfxMCApp]> git.exe push jfxmcapp.gitstack.local
warning: push.default is unset; its implicit value is changing in
Git 2.0 from 'matching' to 'simple'. To squelch this message
and maintain the current behavior after the default changes, use:
git config --global push.default matching
To squelch this message and adopt the new behavior now, use:
git config --global push.default simple
See 'git help config' and search for 'push.default' for further information.
(the 'simple' mode was introduced in Git 1.7.11. Use the similar mode
'current' instead of 'simple' if you sometimes use older versions of Git)
After this Git just hangs for ages?
Update: it appeared in eclipse after adding it git remote add
First: try to use the git command-line client. Git is powerful and evil – and will not tell you any of it’s secrets if you hide it away behind GUIs.
About your question: Now that you set up your gitstack repo as a remote, all you need to do is push. If the push to upstream options are not available, try doing it from the command line: Run the git shell, go to your project dir and run git push.

cannot see committed changes in repo

I have staged my files like this
git add mydir
git add mydir/myfile
and then pushed them to my repo
git remote add origin https://github.com/usename/myrepo.git
git push origin master
When I look at git status -s it says my files have been added, but I cannot see them in my actual repository. Does anyone know whats going on here?
You have not "added" your files to the repository, only to the staging index.
You need to git commit to get your changes from the staging index to the repository.
git status shows you the status of the working tree and staging index. git log shows you the status of the history - in other words, git log will show you what's been committed to the repository.
As an example, see this git status output:
git status
# On branch master
# Changes to be committed:
# (use "git reset HEAD ..." to unstage)
#
# modified: Game.py
#
In this case, we can see that the changes to be committed involve Game.py. Note that these changes haven't yet been added to the repository - they're just staged, ready to be committed, as the git status says.
The next step is to commit these changes we've prepared in the staging index and add them to the repository. git commit is the command to do this.
This answer, as well as the linked Pro Git book, have some excellent reading which will help you understand the setup and steps in committing to a git repository.
I cannot see them in my actual repository.
What do you mean by "actual" repository? I am presuming you mean you can't see a local commit, but there may be some confusion about the repositories you're using.
You're using two repositories, one local and one remote. The remote repository is, in your case, on GitHub. You do your work locally, then git push to remote.
First, local changes and commits
So the steps to get your code changes into the local repository are as follows:
Make changes in your working directory. This is most often writing some code.
Build a commit by staging changes. This is done using git add.
"Save" the commit you've built into the repository. This is done using git commit.
These steps take place **locally*. None of these steps have any affect on your GitHub repository.
Secondly, git push to the remote repository (in this case, your GitHub one).
To get your code from local to remote repositories, git push is used.
Check what remote repositories are known by your local repository: git remote -v.
If the GitHub repository is not shown, you'll need to add it: git remote add <NAME> <URL>.
Because you didn't git clone, the two repositories (local and remote) don't have any commits in common. That's ok; it just means git doesn't automatically know where to push your changes, so you'll have to specifiy: git push <NAME> master:master. That'll push your local master branch to the <NAME> master branch.