linux:git

Differences

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

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
linux:git [2025/06/02 21:23] – external edit 127.0.0.1linux: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. 
- 
-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. 
  
 [[https://githowto.com/|Git How-to]] [[https://githowto.com/|Git How-to]]
  
-==== Stage / Commit / Push ====+===== Stage / Commit / Push =====
  
 <code> <code>
Line 15: Line 11:
 </code> </code>
  
-==== Branches ====+===== Branches =====
  
 Switch branch (option create) Switch branch (option create)
 <code> <code>
-git checkout branch_name +git switch branch_name 
-git checkout -b create_branch_name+git switch -c create_branch_name
 </code> </code>
  
-==== Atom, Git and Rust ====+(''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. When you create a new Rust project using Cargo it automatically initializes a local git repository.
Line 31: Line 29:
 <code> <code>
 cd existing_folder cd existing_folder
-git init //Skip if in a Rust project created with cargo, git is already initialized+git init # Skip if in a Rust project created with cargo, git is already initialized
 git remote add origin <remote_repo_url> git remote add origin <remote_repo_url>
-git add . //required +git add . # required 
-git commit -m "Initial commit" //Feel free to change the message +git commit -m "Initial commit" # Feel free to change the message 
-git push -u origin master //This is what actually pushes.+git push -u origin main # This is what actually pushes (use master if your default branch is still called master)
 </code> </code>
  
-You will be prompted for username and password of owner of the Git distant repository.+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).
  
-Atom has a built-in git feature that will automatically detect git repositories and has a useful GUI. To use it, your project root folder **must be directly** in the project tree manager. It cannot be in a sub-directory or Atom will **not** autodetect the git repository.+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: 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> <code>
-git push --all --set-upstream origin +git push --all --set-upstream origin
 </code> </code>
  
-==== Branching ==== +===== Branching =====
-//The following is still under test and uncertain, but seems to have worked already. The commands are probably not optimized (i.e. git pull calls git fetch already so it may not be required, but this needs additional testing to clear out//+
  
- +To get a branch that exists on the remote repository, fetch the remote data then switch to the branch:
-When creating another branch, to have it appear in Atom run the following command :+
  
 <code> <code>
 git fetch origin git fetch origin
 +git switch <name-of-branch>
 </code> </code>
  
-This will fetch all the data in the origin's repository, which should be your remote repo if everything is configured correctly. +''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.
- +
-Then run : +
- +
-<code> +
-git pull origin <name-of-branch> +
-</code> +
- +
-This should update the local repository to the current tip of the head from the branch you are pointing to. +
- +
-If this does not work, maybe it is required to create the branch in atom with the "new branch" button with an identical name but I doubt so. +
- +
- +
  
-===== Ressources =====+===== Resources =====
  
 [[https://git-scm.com/book/en/v2/Getting-Started-About-Version-Control|Git book]] [[https://git-scm.com/book/en/v2/Getting-Started-About-Version-Control|Git book]]
  • linux/git.1748892233.txt.gz
  • Last modified: 2025/06/02 21:23
  • by 127.0.0.1