More advanced Git commands

Remotes

$ git remote --verbose
$ git remote -v
Checking remote repositories to which you can push.
$ git remote add origin https://code.google.com/p/restful-webservice-training
Adding remote repository with name origin.
This command is used when you already started working on local repository (made few commits), and after a while decided to create a remote one, on code.google or github.
$ git remote remove origin
Removing remote repository with name origin.


Pushing

$ git push origin master
$ git push
Pushing master branch to remote (origin) repository.
Both commands have equal effect. Because origin repository and master branch are default in git.


Pulling

$ git pull
$ git pull origin master
$ git pull c:\dev\repositories\restful-webservice
$ git pull c:\dev\repositories\restful-webservice branch_name
If you are on a branch which is reflected remotely and want to get the latest version of repo. Pulling is a way of getting the latest changes. This command will try to automatically merge your commits with remote repository.
$ git pull --rebase
This command will get the latest version of repo, but instead of merging, will try to rebase you commits with remote repository.


Submodules

Submodule is a very useful feature of git. In situation when you want to use a reference project in that one, you are currently working on. And keep both projects separate from each other. You can find more description about it here. In this kind of situation you can use reference project as a submodule. Here are some tips how to use it.

$ git submodule add git@github.com:pivotal/robolectric.git lib/robolectric
This command add a submodule to project and automatically clone it into path „lib/roboelectric”.
If you run it first time, this command will create file „.gitmodules” in your root directory. In that file there is url – path mapping for all the submodules.


$ git clone --recursive https://code.google.com/p/restful-webservice-training/
Cloning repository with all its submodules. Each submodule is cloned to its location.


$ git submodule
Prints list of registered submodules for this projects.


Forgot to clone recursively?
If you forgot to clone a repo with –recursive flag you can always do it later.

$ git submodule init
$ git submodule update

All you need to run are two commands, one after the other.
To pull submodules content, first you need to initialize it, and then update it.


$ git submodule deinit lib/robolectric
$ git rm lib/robolectric
Removing submodule.
You need to run both this commands one after the other.


Skomentuj

Wprowadź swoje dane lub kliknij jedną z tych ikon, aby się zalogować:

Logo WordPress.com

Komentujesz korzystając z konta WordPress.com. Wyloguj / Zmień )

Zdjęcie z Twittera

Komentujesz korzystając z konta Twitter. Wyloguj / Zmień )

Facebook photo

Komentujesz korzystając z konta Facebook. Wyloguj / Zmień )

Google+ photo

Komentujesz korzystając z konta Google+. Wyloguj / Zmień )

Connecting to %s