linux:git

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
linux:git [2019/05/24 12:25] – created mhlinux:git [2026/10/23 11:08] (current) – [claude] Update git page: drop Atom, GitHub token auth, main branch, git switch, # comments, heading levels claude
Line 1: Line 1:
 ====== Git Basics ====== ====== Git Basics ======
  
-Git is a complicated tool to use, if you don't use it on a very regular basis.+[[https://githowto.com/|Git How-to]]
  
-I prefer using Graphic interfaces that help a lot with git management like in Atom, but here is a recap of basic commands so I remember them when I need.+===== Stage / Commit / Push =====
  
-==== Stage / Commit / Push ====+<code> 
 +git add the.file 
 +git commit -m "The message" 
 +git push 
 +</code>
  
 +===== Branches =====
  
 +Switch branch (option create)
 +<code>
 +git switch branch_name
 +git switch -c create_branch_name
 +</code>
 +
 +(''git switch'' needs git 2.23 or later; on older versions use ''git checkout'' and ''git checkout -b''.)
 +
 +===== Git and Rust =====
 +
 +When you create a new Rust project using Cargo it automatically initializes a local git repository.
 +
 +To connect it with a remote repository follow the basic instructions :
 +
 +<code>
 +cd existing_folder
 +git init # Skip if in a Rust project created with cargo, git is already initialized
 +git remote add origin <remote_repo_url>
 +git add . # required
 +git commit -m "Initial commit" # Feel free to change the message
 +git push -u origin main # This is what actually pushes (use master if your default branch is still called master)
 +</code>
 +
 +Git will ask you to authenticate as the owner of the remote repository. GitHub no longer accepts account passwords for git: use a personal access token (entered as the password) or an SSH key (with an SSH remote URL).
 +
 +Most modern editors (VS Code, Zed...) detect the git repository automatically when the project root folder is opened directly.
 +
 +If you want to set all of your branches to automatically use this remote repo when you use git pull, add --set-upstream to the push:
 +
 +<code>
 +git push --all --set-upstream origin
 +</code>
 +
 +===== Branching =====
 +
 +To get a branch that exists on the remote repository, fetch the remote data then switch to the branch:
 +
 +<code>
 +git fetch origin
 +git switch <name-of-branch>
 +</code>
 +
 +''git fetch'' downloads everything from ''origin'' without changing your files. ''git switch'' then creates a local branch with the same name that automatically tracks the remote one.
 +
 +===== Resources =====
 +
 +[[https://git-scm.com/book/en/v2/Getting-Started-About-Version-Control|Git book]]
  • linux/git.1558693523.txt.gz
  • Last modified: 2025/06/02 21:18
  • (external edit)