What is the conceptual framework of Git? [closed] - linux

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I want to become a Git expert since I use it at work but only half understand it and several times have lost over a day's work because I ran some wrong commands. I've found several tutorials on the internet, but I don't feel like any of them help me actually understand how the application works. All the tutorials say "Here's how to initialize a repo, here's how to make a commit," etc., but they never explain what's happening behind the scenes.
For example, I still don't understand what happens when I push: am I actually replacing the entire repository at the remote location with the one in my commit? By the way, is a commit and actual copy of a version of the repository or is it just information about the changes between my copy and some other version? I want to understand those types of things and I haven't found a tutorial that helps much.

I've recently found myself in the same boat and did a whole bunch of research.
The first thing you need to conceptually understand is that basically, Git works with three areas:
The Development Area, The Staging Area, and finally The Repository (Repo)
The Development Area:
This is where your files are held on your computer. When you install Git you essentially get a framework of commands that will allow you to designate what directories on your computer are to be considered a development area (along with the rest of the commands to do things -- we will get to that in a bit). To designate a Directory on your system as a place you want Git to keep track of you use 'git init'.
The Staging Area:
So this is what threw me off at first. When you make a change to a file in the Development area, you send it to the Staging Area before you send it to the Repository. Thing of this as a temporary space for changes. The reason this is done is so that you can make a number of changes and Commit them as a Set of changes for a Project. This is actually really helpful because it allows you to control what updates and commits you send out. To send a file you change in your Development Area to the Staging Area type "git add filename.ext" or if all the files in a directory are ready to go to the Staging Area just type "git add ."
The Repository:
When you are ready to send all of your changes from the Staging Area to the Repository you use the command: git commit -am "Message explaining the changes / what your are adding, etc." Then "git push"
Let Git Help You!
Things in Git can be confusing at first, so I also recommend letting Git help you out a bit. You can always ask Git what the status of your Working Area / Development Area by using the command "git status". This will guide you.
As you know, one of the biggest appeals of Git is getting someone's code from an Open source project, working on it locally, making changes and then asking them if they will take the changes you have made - adding them into the project.
The concept behind this is to clone a project to your local system, then do everything above.
Look, that is a simple overview and you obviously will have to supplement it. I recommend checking out Derek Banas' Youtube tutorials on Git here: https://www.youtube.com/watch?v=r63f51ce84A&list=PLGLfVvz_LVvQHO1PfyscjIPkNJjgHsLyH

So you want to be a GIT expert...
First, let me say that when I began switching over to GIT from Subversion I had the same questions. My first recommendation is a textbook, this one got me over the hump Version Control with GIT (looks like it's $3 now!). I have found tutorials on GIT to be very command-centric.
About particulars you mentioned:
git init : initializes the current directory as the root directory for the project; basically it puts a .git/ directory there which where all the inner-workings of the repo are stored.
Pushing : you are not replacing the repository, you are PUSHING your lasted commits (git objects,files,modifications,etc) so remote is aware of the target branches history log
What is a commit? Think of a commit like a saved state that you can always go back too, but it's a little more than that since it can be compared against, and retain other info like who did the work and what time it was done.
I'd like to know if your switching over from another VCS cause if not it would make sense to do primary research on VCS concepts. GIT has fundamental differences which make it superior most of the time.
Last note is GIT doesn't store your files, it stores hashes of your files. -Good luck.

Related

Clearcase multisite vs Gitlab.... anything?

The company I work for uses Clearcase, even though it was EOL'd on the platforms in which we run it years ago. It is ancient and fragile tech, but one thing it does have is a multisite support that allows for the synchronization of air-gapped repos. Because of security issues, we use secure USB sticks to copy packets and take them to the other side, then apply them with scripts.
Developers and DevOps people want to make a business case to migrate to GitLab, but I cannot find any mention of a feature in GitLab that would allow me to do easily do this. There's something about bundles, but the info I have found is years old and it doesn't seem like too many people are using it.
Does GitLab not support this? Simple synchronization of one repo to another over an air gap using some sort of secure media? If so, it's no wonder so many teams are still using ClearCase.
While not exactly easy, air-gap updates of Git repository is possible through the git bundle command.
It produces one file (with all the history, or only the latest commits for an incremental update), that you can:
copy and distribute easily (it is just one file after all)
clone or pull from(!)
This is not tied to GitLab, and can be applied to any Git repository.
From there, I have written before on migration from ClearCase to Git, and I usually:
do not import the full history, only major labels or UCM baselines
split VObs per project, each project being one Git repository
revisit what was versioned in Vobs: some large files/binaries might need to be .gitignore'd in the new Git repository.
You would not "migrate views": they are just workspace (be it static or dynamic). A simple clone of a repository is enough to recreate such a workspace (static here).

GitLab: include branches from a similar project to local repo

i am pretty new to GitLab and have a question concerning branches and updating the local repo.
Around two weeks ago i cloned a project and did a bit of work on it (mainly added one branch). Other people also have local repositories of that same project (hope that makes sense). Now I would like to clone only a single branch of one of those local repos made by other people and include it into my local repo.... How do i do this? Ofc I can clone the branch into a different directory, but my goal is only having one directory with only one name in which that branch is contained, so that I can switch between the branches I had from the beginning and the new branch I cloned.
Basically, in order to be more clear: There is a project called a_proj. Me and another person have cloned a_proj and therefore have local repos on which we do work. The other person added a branch called a_branch which I don't have. I want to include a_branch into my version of a_proj.
Additionally i have a different question concerning updating a branch. What if some person does some work on their local version of a branch I also have on my Local and I want to include their changes, or even change my branch to their version. How could I do that?
Thank you a lot for any helpful answers on this topic. If there is constructive critic about this post or the way I think about GitLab I am happy to hear it, as already mentioned, this is a pretty new topic to me and I want to learn wherever i can!
Okay, i figured it out. Was pretty easy actually once one knows what to do. For information, i am using GitKraken so it might be different for different environments but essentially the idea is to add the other person's project as remote, (where ones own project should also be a remote named origin). Then one can add any branch of those remotes to the Local project, simply by checking out the wanted branch. It then gets added to the Local repository on which work can be done.
I guess that isn't anything new to anybody who uses GitLab but i'll just leave it here in case some noob (Like me) also has this question.

import entire GitLab Cloud project to new GitLab instance

I have some projects set up on GitLab Cloud, complete with issues, wiki pages, etc. I've recently set up an internally hosted gitlab instance. I'd like to bring these projects over from GitLab Cloud to the internal GitLab instance.
Bringing over the git repos seems easy enough (change the remote and push), but I don't see how to bring over the wikis and issues.
In general it seems like this isn't possible. (There's a GitLab Feedback for it here.)
However, the project wiki's seem to be their own git repos, which you can see on the Git Access tab. While that doesn't solve issues/snippets, it gets you part of the way there.
I don't know how to transfer over issues as I have not had to do that yet, but passing over the wiki is not that difficult.
On your old gitlab instance you will notice two repositories for your project (let's pretend your wiki is oldproject), one will say something like oldproject.git and oldproject.wiki.git.
The general path to the repositories where you can see the names I am talking about (let's assume user-name is "myaccount") can be found here:
/home/git/repositories/myaccount/
or (if using the omnibus installer):
/var/opt/gitlab/git-data/repositories/myaccount/
I presume you already know how to transfer over oldproject.git. You do the exact same thing with the wiki, only you create a bundle file out of oldproject.wiki.git:
git clone http://gitlab-instance-ip/user-name/oldproject.wiki.git
cd oldproject.wiki
git bundle create oldproject-wiki.bundle --all
Now initialize your new project in gitlab...I presume you already know how to do that as you suggested in your question that you know how to import the files from your project over to the new instance without problem. Now repeat for the wiki:
git clone http://new-gitlab-ip/user-name/newproject.wiki.git
cd newproject.wiki
git pull /path/to/oldproject-wiki.bundle
git push -u origin master
I had a very similar problem to yours where I didn't see that anything was actually "pushed". When I went back to the gitlab project I noticed that it was in fact updated with the wiki. See here if you think it will help: Importing Gitlab Wiki to a new Gitlab Instance
Good luck!

JGit : connect to distant repository

I searched through Google, forums and JGit user guide but couldn't find how to connect to a distant repository with the API.
Anyone has an example or just an idea on how to do that?
Thanks for your help.
Currently, JGit 2.0.0-SNAPSHOT does only offer
org.eclipse.jgit.storage.file.FileRepository
org.eclipse.jgit.storage.dfs.InMemoryRepository
concrete Repository classes, meaning that since org.eclipse.jgit.api.Git takes a Repository, it is not possible to work remotely. Since Git by itself is not designed to operate remotely in the way I think you mean, I doubt we will see such a feature any time soon.
MORE ON THAT:
Consequently, you will need to clone locally. You do that by issuing
Git.cloneRepository()
.setURI(myRemoteURIString)
.setDirectory(new File(myLocalPathString))
.call();
However, for reasons of consistency in Git you should clone a bare repository only, so a non-bare repository in a remote location, while not technically, is practically inaccessible.
I am not sure I understand the question since Git is made for accessing other repositories, this is what is meant by "Git is distributed".
If you want to connect to ONE distant repository, then yeah you should clone it.
I don't know if that is what you are looking for, but you can also use multiple remotes. Adding one more is done with Git using git remote add <remote_name> <remote_uri>. As for Jgit, I unfortunately can't remember the code to do it simply, but you can figure this out.
At least it's possible by modifying the configuration, calling getConfig() from a Repository object and then calling setString(...) on it - don't forget to save the configuration in the end. But before modifying the configuration, I think you should first get to know more about Git and JGit.
I recommend you to read more about it, and play a bit with your repository. Take a look at this article : http://caiustheory.com/adding-a-remote-to-existing-git-repo .
Another one that will help you down the road is How do I do the equivalent of “git remote update” with jgit?
Maybe someone else knows exactly which commands to run and can help.

SVN server hosting company shutting down, and I need a backup of repository

I just logged onto http://www.ezsvn.com, that hosts my SVN repository. I have been paying monthly for hundreds of commits.
They're shutting down, and their support is nonexistent.
Can I get a backup of my repository from my machine? I’m using Windows.
If you have shell access:
http://wiki.archlinux.org/index.php/Subversion_backup_and_restore
If you don't have shell access (look at both the original answer and also the comments re: svnsync):
http://moelhave.dk/2006/07/remote-mirroring-a-subversion-svn-repository/
If you have access to run svnadmin on their server, it'll be no problem, and I see Dav has already linked to instructions for that.
Now, if you don't have access to run svnadmin, as far as I know it's not possible to use the SVN client itself (maybe TortoiseSVN for you) to copy the entire repository. (EDIT: never mind, I guess that was wrong. I'll leave the git info here just for the fun of it though.) But you can convert a whole Subversion repository to git, and here are instructions for doing that: http://pauldowman.com/2008/07/26/how-to-convert-from-subversion-to-git/ From there, you might be able to convert the git repository back into an SVN repository on another server. I know it's not really the answer you were looking for but if nothing else works, it will at least let you save your project's history in some form. (And hey, you could take it as an excuse to switch to distributed version control, which is all the rage these days)
If you really want/need the full history of your repository, you'll have to either get a dumpfile from the provider or get it yourself - some of the responses so far have addressed this already.
Another option: if you are not concerned with past revisions, but want your repo at it's latest state, just checkout the head revision, and export it to a separate location on your computer. That way, you have all your work to this point. You could then keep that as a backup, or possibly create an SVN account elsewhere, and import the exported copy into a fresh repo, then you would be back in business.

Resources