Creating a bare repository
1 2 3 4 5 |
mkdir remote_repose1 remote_repose2 cd remote_repose1 git init --bare cd ../remote_repose2 git init --bare |
Creating a repositiy
1 2 3 |
mkdir repos1 repos2 cd repos1/ git init . |
Managing remotes
You need to know how to handle your remote repositories in order to be able to work on any Git project. Remote repositories are copies of your project which are hosted elsewhere on the Internet or the network. You can have several of them,
Adding remote
git remote add <remote-name> <url>
1 2 3 |
git remote add origin ../remote_repose1/ date > index git add . |
git push <remote-name> <branch>
explicitly says “push the local branch ‘master’ to the remote named ‘origin'”. This does not define a persistent relationship, it just executes a push this one time. Note that the remote branch is assumed to be named “master”.
1 2 3 |
git commit -m 'index added' git push origin master git remote show origin |
Or you can use git push --set-upstream origin master
(or the short version: git push -u origin master
) which is the same thing as git push <remote-name> <branch>
, except it first adds a persistent tracking relationship between your local branch “master” and the remote named “origin”. As before, it is assumed the remote branch is named “master”, later on you can just use git push
You can add more remotes:
1 2 3 4 |
date>index git add . git commit -m 'index updated' git push gitlab master |
Viewing remotes
1 2 3 |
git remote -v git remote show origin git remote show gitlab |
Renaming and Removing Remotes
1 2 |
git remote rename gitlab git_lab git remote git_lab |
Changing a remote’s URL
git remote set-url <existing-remote-name> <new-URL-for-the-remote>
changes an existing remote repository URL.
1 |
git remote set-url origin https://github.com/USERNAME/REPOSITORY.git |
Cloning
1 2 |
cd repos2/ git clone ../remote_repose1 . |
When you clone your repository, you don’t need to run
git push -u <remote-name> <branch-name>
because origin/master
is already set up as master
‘s upstream branch. In other words, master
is already set to track origin/master
.
Checking the progress of cloning
1 |
git clone https://github.com/PointCloudLibrary/pcl --progress |