I'm using git here and there when I need some basic VCS functionality, but I've yet to fully understand how certain things work in Git.
Git, unlike SVN, is decentralized so that I could start a repository in one place and work with it locally, and then push my changes to another repository, at least that's how I understand it.
I'd like to know a few key things:
If I want to create a new repository on my local machine, and than push
(?) it to the server (it either has or doesn't this repo already), what are the actions needed?
Do I need a web-server to interact with remote repos?
How do I push/pull from/to a server that I have SSH access to?
Hopefully the reply would be short and to the point - man pages are great by they don't always convey what they need and sometimes have info that I don't need. So I hope you'll forgive me and my question even if it was asked/answer many times before.
Before anything else, understand how to configure ssh access (in
general, not just for git
) to your server, such that you can run
something like:
ssh myserver uptime
And have it run the remote command without prompting you for a
password. This will make your life with git
much more pleasant.
If I want to create a new repository on my local machine, and than push (?) it to the server (it either has or doesn't this repo already), what are the actions 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 commit some changes.
$ git add a-file-i-editied
$ git commit -m 'this is a change'
Add a remote -- i.e., a reference to a remote repository:
$ git remote add origin you@yourserver:path/to/repo.git
Where you is your userid on the remote server and yourserver is the hostname (or ip address) of the remote server.
Push your changes to the remote repository:
$ git push origin master
Where origin is the name you have your remote in the previous step, and master is the branch that you're pushing.
Do I need a web-server to interact with remote repos?
Note the lack of any web server in the previous example. Git can
operate over http/https, but it is more often used over ssh. Git also
provides a native git protocol that can be used for providing
anonymous read-only access to repositories; the git-daemon
implements this protocol.
How do I push/pull from/to a server that I have SSH access to?
This is pretty much the example I've provided, but let me know if you would like more detail in any of the steps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With