git

Table of Contents

Git is a version control tool

1. utilities

1.1. commit with message

git commit -m "message"

2. Basic Workflow

2.1. create branch

https://git-scm.com/book/en/v2/Git-Branching-Remote-Branches

  1. create local branch
    • terminal git branch branchname from the branch you want to start off (git branch will duplicate the current branch and give it a new branchname). If the branch is already created in the remote, checkout to its tracking-branch, and branch from there
    • magit b l checkout local branch or b c create branch would let you decide which branch/tracking-branch to start off.
  2. push local branch to origin(remote repo) and create it at the remote repo

2.2. pull request

pull request is basically telling a project maintainer to pull your code to try it out on their local machine, and decide if to merge.

In order to do that, you need to provide with project maintainer the following informations:

  • your repo’s url and the start/end commit of your patch, for the project maintainer to perform git pull

Esssentially, it is not part of git’s utility, and in its whole done by people by hand: you send message to the project maintaner about your patch, project maintainer try it out and tell you to change something, reject it, or merge it.

git book have this example

$ git request-pull origin/master myfork
The following changes since commit 1edee6b1d61823a2de3b09c160d7080b8d1b3a40:
Jessica Smith (1):
        Create new function

are available in the git repository at:

  https://githost/simplegit.git featureA

Jessica Smith (2):
      Add limit to log function
      Increase log output to 30 from 25

 lib/simplegit.rb |   10 +++++++++-
 1 files changed, 9 insertions(+), 1 deletions(-)

the command generates this message for you to include in your email to the project maintainer. The git repository is not meant to be local repository, but a public one that the project maintainer would have access to(you can tell from the domain name)

In various git service providers, they made services to make pull-request in the same platform which is roughly like this, just they have buttons to automate some of the commands listed here:

    git checkout -b userblah-test master (added master here and in the next line)
    git pull https://github.com/userblah/myproject.git master
    look at changes
    git checkout master
    git merge userblah-test
    git push
  • mainly pulling and merging

2.3. new repo

2.3.1. start from scratch

best to clone from remote.

  1. start a repo from sourcehut/github/codeberg…
  2. git clone ssh-link-to-git-repo

2.3.2. git init on a existing project

  1. create remote
  2. get in the project
  3. git init
  4. git add . (note if there’s in-project)
  5. git commit (first commit)
  6. git remote add origin ssh-link-to-git-repo
  7. git pull --allow-unrelated-histories
  8. git

Backlinks

Author: Linfeng He

Created: 2024-04-03 Wed 20:17