git使用分支细节

一、使用用户名和密码连接远程服务器时需要注意用户名

       如果使用相同git username选项时用户名,认证一直失败;这个用户名要注意;但具体不清楚怎么寻找准确的,只是多尝试几个可能,就解决了问题;

 

二、创建分支时,上传文件到分支需要使用如下命令:
 

       首先查看有没有你新添的分支:
          git branch -a
(带有*的分支是当前分支,如果是你需要提交的分支,后面就不需要进行下去了)

       如果没有,就需要更新:
          git fetch origin --prune

      然后需要切换到指定的分支,否则默认是master分支:

      git checkout -b branch_01

       最后提交:
     git push origin branch_01

 

三、创建ssh:

 1、To generate a new SSH key pair, use the following command:

      Git Bash on Windows / GNU/Linux / macOS:

        ssh-keygen -t rsa -C "your.email@example.com" -b 4096
       Windows:

      Alternatively on Windows you can download
     PuttyGen
     and follow this documentation article to generate a SSH key pair.
2,、you will be prompted to input a file path to save your SSH key pair to.

    If you don't already have an SSH key pair use the suggested path by pressing
   enter. Using the suggested path will normally allow your SSH client
   to automatically use the SSH key pair with no additional configuration.

3、If you already have a SSH key pair with the suggested file path, you will need
to input a new file path and declare what host this SSH key pair will be used
for in your .ssh/config file, see Working with non-default SSH key pair paths
for more information.


4、Once you have input a file path you will be prompted to input a password to
secure your SSH key pair. It is a best practice to use a password for an SSH
key pair, but it is not required and you can skip creating a password by
pressing enter.

NOTE: Note:
 If you want to change the password of your SSH key pair, you can use
 ssh-keygen -p <keyname>.


5、The next step is to copy the public SSH key as we will need it afterwards.

To copy your public SSH key to the clipboard, use the appropriate code below:

macOS:

pbcopy < ~/.ssh/id_rsa.pub
GNU/Linux (requires the xclip package):

xclip -sel clip < ~/.ssh/id_rsa.pub
Windows Command Line:

type %userprofile%\.ssh\id_rsa.pub | clip
Git Bash on Windows / Windows PowerShell:

cat ~/.ssh/id_rsa.pub | clip


6、The final step is to add your public SSH key to GitLab.

Navigate to the 'SSH Keys' tab in your 'Profile Settings'.
Paste your key in the 'Key' section and give it a relevant 'Title'.
Use an identifiable title like 'Work Laptop - Windows 7' or
'Home MacBook Pro 15'.

If you manually copied your public SSH key make sure you copied the entire
key starting with ssh-rsa and ending with your email.

Optionally you can test your setup by running ssh -T git@example.com
(replacing example.com with your GitLab domain) and verifying that you
receive a Welcome to GitLab message.

ssh -T git@example.com   这个example跟自己的邮箱无关,而是git代码的域名有关;可以打开服务器网址,就可以看到域名;我总是输入自己的邮箱名,导致一直出错;而这里会加载sra的东西,如果前面生成ssh步骤设置了密码,这里就会要求输入密码;(Once you have input a file path you will be prompted to input a password to secure your SSH key pair. It is a best practice to use a password for an SSH key pair, but it is not required and you can skip creating a password by pressing enter.)

三、使用:

注意:使用ssh的地址不同于原来的http地址:ssh是用git开头的地址

git remote -v:如果是http开头,说明仍然使用http的协议;

修改:git remote set-url origin  ssh地址;例如:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值