git command

connet to uoft server from pycharm

settings –> SSH Configurations –> add one

1
2
3
4
Host: comps0.cs.utoronto.ca
Port: 22
User name: cs login name
Password: cs passport

–> Test Connection

Then, go to the Terminal. There is a drop-down list. Choose the ssh server you just added. Then you are connected to the server.

push a folder

If there is a local folder in your laptop and you want to push it into a github repository.

  1. first, build a new repository in your github account
  2. copy the ssh this new repository
  3. (local folder) git bash
    1
    2
    3
    4
    5
    6
    7
    8
    $ git init
    $ git remote add origin git@github.com:freya-popo/csc2529-hw3.git # connect the local folder to the github repo
    $ git pull origin master # pull the github repo to local repo, keep align
    $ git add . # add files to the local repo
    $ git commit -m "first push" # commit files to local repo
    $ git push origin master # push the local repo to the github repo

    # if the file is in the previous folder which has been connected to the github repo, only the last 3 steps need to be done

delete files from the github repo

1
2
3
4
$ git pull origin master  #本地同步远程仓库,将远程仓库里的内容拉下来
$ git rm -r --cached 文件名 #删除文件
$ git commit -m “delete dir#提交并添加说明
$ git push origin master #将本次更改更新到github项目上去

push files from a server

In this assignment, I want to use a remote server to run a python program.

First of all, ssh to the server.

Then clone the github repo

1
2
3
$ git clone https://github.com/freya-popo/csc2529-hw3.git
# from the https address
# if clone from the ssh address, there might be a error: git@github.com: Permission denied (publickey), which means we need to set up the ssh

After running the python program, I got a new picture and wanted to upload this picture to the github repo.

1
2
$ git add.
$ git commit -m "second push"

The files is in the server’s local repo now. But I got an error when I pushed them by this command.

1
2
$ git push origin master
# an error occurred: fatal: Authentication failed for 'https://github.com/freya-popo/csc2529-hw3.git/'

I think it is because the user is changed and I need to use a new token.

So, I need to generate a new token from my github account.

Settings –> Developer Settings –> Personal access tokens –> Tokens(classic) –> generate new token –> generate new token (classic)

tips: remember to select appropriate scopes or another error will occur.

1
2
remote: Permission to freya-popo/csc2529-hw3.git denied to freya-popo.
fatal: unable to access 'https://github.com/freya-popo/csc2529-hw3.git/': The requested URL returned error: 403

Then we got the token, copy the token and run the push command again:

1
2
3
$ git push origin master
Username for 'https://github.com': freya-popo
Password for 'https://freya-popo@github.com': 'token just got'

Then you can see the new files in the github repo.


git command
http://freya-popo.github.io/2023/10/17/git-command/
Author
freya-popo
Posted on
October 17, 2023
Licensed under