Git Essentials for Beginners

I use git here and there when I need some basic VCS functions, but I haven't figured out how some things work in Git yet.

Git, unlike SVN, is decentralized, so I can run the repository in one place and work with it locally, and then make changes to the other repository, at least as I understand it.

I would like to know a few key things:

  • If I want to create a new repository on my local computer, and not push (?) On the server (it either has or does not do this repo already), what actions are needed?

  • Do I need a web server to interact with remote repositories?

  • How do I push / pull from / to a server to which I have access to SSH?

I hope the answer is short, and the dotted pages are great, they don’t always convey what they need, and sometimes they have information that I don’t need. Therefore, I hope that you will forgive me and my question, even if he had been asked / answered many times before.

+4
source share
2 answers

Before anything else, understand how to configure ssh access (in general, and not just for git ) on your server so that you can run something like:

 ssh myserver uptime 

And start the remote control without asking for a password. It will make your life with git lot nicer.

If I want to create a new repository on my local machine and click (?) On the server (it either has or does not execute this repo already), what actions are needed?

On the remote server:

  • Create the target repository:

     $ mkdir -p path/to/repo.git $ cd path/to/repo.git $ git init --bare 

On your local system:

  • Create your repository ...

    $ mkdir myrepo

    $ cd myrepo

    $ git init

    ... and make some changes.

    $ git add a-file-i-editied

    $ git commit -m 'this is a change'

  • Add remote - that is, a link to the remote repository:

    $ git remote add origin you@yourserver :path/to/repo.git

    If you are your user ID on a remote server, and your server is the host name (or IP address) of the remote server.

  • Push your changes to the remote repository:

    $ git push origin master

    Where the origin is the name in which you have the remote control in the previous step and the master is the branch that you click on.

Do I need a web server to interact with remote repositories?

Note the absence of any web server in the previous example. Git can work on http / https, but is most often used for ssh. Git also provides its own Git protocol, which can be used to provide anonymous read-only access to repositories; git-daemon implements this protocol.

How do I push / pull from / to a server to which I have SSH access?

This is pretty much an example that I have provided, but let me know if you would like more detailed information at any stage.

+9
source

What you asked in the question is the most fundamental aspect of Git and Github. Let me take the exact steps for what you requested.

1) To create a new Git repository, go to the project folder using the terminal (or another equivalent program for your OS) / Open the terminal in the folder and enter the following command

 git init 

This initializes your project with an empty Git repository.

Now you can make changes to your project and write these changes to separate commits. Here how you do the commit

 git commit -m "YOUR COMMIT MESSAGE" 

To redirect your repo to github / any other Git hosting service, you first need to add the remote repository URL as follows

 $ git remote add origin you@yourserver _url.git 

Now it is ready to click. Run the following command to do this

 $ git push origin master 

2) You need a server to interact with Git

Eli answered this very well, but simply summed up. No no. Most people use an existing service like Github, Bitbucket, Gitlab, etc. To host your repositories, in which case you just need to interact with the remote repo using the remote URL.

3) How to push / pull from a remote repo?

First you need access to the repo if it is private (if you are not good to go). Then enter the repo url, it should look something like this.

 https://github.com/YOUR_USERNAME/YOUR_PROJECT.git (This URL example is from github) 

Next, you need to clone it to the local machine as follows

 git clone https://github.com/YOUR_USERNAME/YOUR_PROJECT.git 

Now that you have cloned it, make the necessary changes and just click on it using the command below.

There's more to version control than just the basics. If you want to know more, there is an interactive site try.imtqy.com , which you can find to learn the basics or read this article that I have written on the same one, it should help you get started.

Here is the link https://www.techlila.com/version-control-git/

+1
source