User Tools

Site Tools


cheatsheet:git

Differences

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

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
cheatsheet:git [2023/02/14 10:48] kamaradskicheatsheet:git [2023/07/24 08:46] (current) – [other common commands] kamaradski
Line 46: Line 46:
 </code> </code>
  
-===== other common commands ===== 
  
-git init: Initialize a new Git repository.+===== Use git stash to move code between branches =====
  
-git clone <repository_url>: Clone an existing Git repository.+A common use case that I use git stash for is when I make changes in the wrong branch that are bigger than just a few lines and thus not so easy to copy/paste into the next branch.
  
-git add <file_or_directory>Stage changes to a file or directory for the next commit.+Here is how I do it:
  
-git reset <file_or_directory>: Unstage changes to a file or directory.+<code> 
 +git stash // stash your changes 
 +git checkout feature_branch // Navigate to your feature branch (or create and checkout a new branch: git checkout -b feature_branch 
 +git stash apply // apply the stashed changes 
 +git add . 
 +git commit -m "Your commit message here" 
 +git stash drop // delete the stash in case yuo no longer need it 
 +</code>
  
-git commit -m "<message>": Commit staged changes with a message. 
  
-git log: Display the commit history of the repository.+===== other common commands ===== 
 + 
 +  * ''git init'': Initialize a new Git repository. 
 +  * ''git clone <repository_url>'': Clone an existing Git repository. 
 +  * ''git add <file_or_directory>'': Stage changes to a file or directory for the next commit. 
 +  * ''git reset <file_or_directory>'': Unstage changes to a file or directory. 
 +  * ''git commit -m "<message>"'': Commit staged changes with a message. 
 +  * ''git log'': Display the commit history of the repository. 
 +  * ''git status'': Display the current status of the repository, including staged and unstaged changes. 
 +  * ''git diff'': Display the difference between the current state and the last commit. 
 +  * ''git checkout <branch_or_commit>'': Check out a different branch or commit. 
 +  * ''git branch'': Display a list of local branches. 
 +  * ''git branch <branch_name>'': Create a new branch. 
 +  * ''git checkout -b <branch_name>'': Create and checkout a new branch. 
 +  * ''git merge <branch_name>'': Merge changes from another branch into the current branch. 
 +  * ''git rebase <branch_name>'': Rebase the current branch on top of another branch. 
 +  * ''git fetch'': Download new changes from the remote repository. 
 +  * ''git pull'': Fetch and merge changes from the remote repository. 
 +  * ''git push'': Upload local changes to the remote repository.
  
-git status: Display the current status of the repository, including staged and unstaged changes.+===== .git/config =====
  
-git diffDisplay the difference between the current state and the last commit.+Random stuff one can use in their git config file~/somerepo/.git/config 
  
-git checkout <branch_or_commit>: Check out a different branch or commit.+==== User details ====
  
-git branch: Display a list of local branches.+<code> 
 +[user] 
 +  email = username@example.com 
 +  name = username 
 +</code>
  
-git branch <branch_name>Create a new branch.+You can add this manually, or use the cli commands to populate the file with this information, like so:
  
-git checkout -b <branch_name>: Create and checkout a new branch.+<code bash> 
 +git config user.email "[email protected]" 
 +git config user.name "username" 
 +</code>
  
-git merge <branch_name>: Merge changes from another branch into the current branch.+==== Aliases ====
  
-git rebase <branch_name>: Rebase the current branch on top of another branch.+Setting up some short-cut commands for frequently used commands
  
-git fetchDownload new changes from the remote repository.+<code> 
 +[alias] 
 +  st = status 
 +  ci = commit 
 +  br = branch 
 +  co = checkout 
 +  df = diff 
 +  lg = log -p 
 +  lol = log --graph --decorate --pretty=oneline --abbrev-commit 
 +  kama = log --graph --pretty=format:\"%h - %cr - %cN - %s - %b\" --all 
 +  ls = ls-files 
 +</code>
  
-git pull: Fetch and merge changes from the remote repository. 
  
-git push: Upload local changes to the remote repository.+==== Formatting ====
  
-git stash: Save changes that have not yet been committed to a temporary stash.+Funky colors
  
-git stash apply: Apply changes from a stash to the working tree.+<code> 
 +[color] 
 +  ui = auto 
 +[color "branch"
 +  current = yellow reverse 
 +  local = yellow 
 +  remote = green 
 +[color "diff"
 +  meta = yellow bold 
 +  frag = magenta bold 
 +  old = red bold 
 +  new = green bold 
 +  whitespace = red reverse 
 +[color "status"
 +  added = yellow 
 +  changed = green 
 +  untracked = cyan 
 +</code>
  
-git stash drop: Remove a stash from the stash list. 
cheatsheet/git.1676371719.txt.gz · Last modified: 2023/02/14 10:48 by kamaradski