博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Git Tutorial 4 - Goto Remote Repository
阅读量:6692 次
发布时间:2019-06-25

本文共 4368 字,大约阅读时间需要 14 分钟。

Eventially I'm going to push my files from local repository to remote repository. Sounds interesting and exciting because that means someone else on the network can share my files and contribute their talents to the repository, to the project. Let's take a look at the picture below

figure 4.1

Obviously we need the command git push. But before using this command to push files to remote repo, I need to create a repo in remote Git site. There are many Git site on the network, such as Github, bitbucket as so on. You could choose anyone you perfer. To me I choose bitbucket here to take an example.

I won't give your any detail info about how to open the website, create an account and sign in untill we get to the step of creating a repo in the website. Let's see my screen when I'm about to create a repo on the site bitbucket.

figure 4.2

Then create repo by clicking the button 'Create repository' at the bottom. You can see the screen 'Repository Setup' as below..

figure 4.3

The example of command line will be shown out when you click the link "I have an existing project". Why should we choose to click this item rather than the other one "I'm starting from scratch", that's because we have done some steps in our previous episodes, such as create local repo, add and commit files to local repo, we don't need to start from scratch. Easy to understand, right? Before running the command instructions bitbucket provides as above picture shows us. Let's think about what the command git remote does. Run the command to check what you can see

git remote git remote -v

You'll see there's nothing return in your terminal if you've never used it to do anything yet. 

 

For each remote repo you have a full URL to point to and you must use it in you command line when you're doing anything to a remote repo. But full URL is too long to remember and to type quickly, so we need an alias to take the place of an URL as well as we did in any programming language where we call variable. OK, now I'm going to create an alias for the URL of my project gittutorials on bitbucket. First I cd to my working directory and type the following command as you can see in figure 4.3

git remote add origin https://vjianwang@bitbucket.org/vjianwang/gittutorials.git

You can think this line as a definition and initialization for alias 'origin' which now is pointing to project tutorials on bitbucket. Don't worry about how to figure out what the URL is. Git remote site, here is bitbucket, will provide you once you create a repo on it. After running the command, type the git remote to see if any differences there from last running

figure 4.4

 

Don't be puzzled if you see the URL twice for fetch and push, because Git consider you might be a geek who want ot customize fetch and push to use different protocols. If you don't care about it just skip the point. Just remember to use a different alias next time in case you have another project to be pointed to. Of course if you insist to use the same alias, you can use the command remote rm to remove the previous URL pointing and remote add it again

git remote rm origingit remote add origin https://vjianwang@bitbucket.org/vjianwang/kawayi.git

or you can use remote rename to get retain the URLs pointing to project gittutorials

git remote rename origin newguygit remote add origin https://vjianwang@bitbucket.org/vjianwang/kawayi.git git remote -v

There would be in all 2 projects and 4 URL display

figure 4.5

 

Now we come back to use alias origin to point to project gittutorials and do the following push work. The push command as below

git push origin master

The command I use is a little bit different from the one bitbucket provides in figure 4.3 . The main difference is that I push only branch master since I don't have any branch else in my local repo and bitbucket's command push all your branches you have in your local repo. When I run the command above, system ask me to type password for my account on bitbucket and then it did the push process untill finish.

figure 4.6

As the picture above shown, a new branch was created and the push was happening between master in local to master in remote. Browse the bitbucket to check my project gittutorials.

figure 4.7

I'm very happy to see all 3 files in my local repo now are locating in the remote repo as we expect.

 

转载于:https://www.cnblogs.com/vjianwang/p/gittutorial4.html

你可能感兴趣的文章
DNS服务器维护命令
查看>>
六、用户与权限
查看>>
面向机器学习数据平台的设计与搭建
查看>>
centos6.7 编译安装mysql-5.6.27
查看>>
spring cloud 整合zpkin问题
查看>>
Maven下载慢的解决方案
查看>>
我的友情链接
查看>>
Android 核心分析 之七------Service深入分析
查看>>
Regsvr32使用方法
查看>>
柱形图Demo
查看>>
编辑器
查看>>
关闭windows的默认共享
查看>>
react开发环境搭建
查看>>
数据库读写分离
查看>>
社交是微信营销
查看>>
2008 R2 证书服务器应用详解
查看>>
hive 动态分区太多问题
查看>>
Windows Server 2008 RemoteApp(二)---部署激活远程桌面授权服务器
查看>>
读取日志文件开发总结
查看>>
IOS --React Native
查看>>