Eridian
eridian.xyzx.comGitHub
  • 📖Eridian Docs
  • Ethereum Dev
    • ✏️Ethereum Notes
      • 🎛️Technical Basics
      • 🪧Ethereum Addresses
      • 📚Ethereum State Explained
      • ⛽Gas Fees Explained
    • 🔧Useful Tools
      • ☁️Ethers
      • *️⃣Ethernal
    • 📝Solidity Notes
      • ❔Interview Questions
        • 🟢1. Easy - Interview Questions
        • 🟠2. Medium - Interview Questions
        • 🟡3. Hard - Interview Questions
        • 🔴4. Advanced - Interview Questions
      • 💡Note Ideas
      • ABI
      • abi.encodePacked
      • Abstract Contracts
      • Arrays
      • Casting
      • CEI - Checks, Effects, Interactions
      • Comments (NATSPEC)
      • Constructor
      • Contract Structure & Versions
      • Data - Storage vs Memory
      • Data - Storage Layout
      • Enum
      • Errors (require & revert)
      • Events
      • EVM Opcodes
      • External Contract Interaction
      • 🏗️External Dependencies
      • Functions
      • Function Modifiers
      • If / Else / For / While Loops
      • Inheritance
      • Interfaces
      • Keccak256
      • Library
      • Mappings
      • msg.sender
      • Objects & Types
      • OpenZeppelin
      • Payable
      • Public State Variable vs Function
      • Receive & Fallback
      • Security
      • Self Destruct
      • Send ETH (transfer, send, call)
      • Stack Too Deep
      • Structs
      • Style Guide
      • Time Units
      • Try / Catch
      • Typecasting
      • Using Directive
      • Variables, Consts & Immutable
      • Withdraws
    • ⚒️Foundry Notes
      • 📖Docs & GitHub Pages
      • 🤝Useful Commands
        • 🔨Anvil
        • 🪄Cast
        • 🔥Forge
      • 🧪Tests
        • Cheatcodes
      • 📝Useful Scripts
        • Deploy Contract Using Hex
    • 👾DeFi Challenges
      • 👨‍🚀Ethernaut
        • Ethernaut - Template
        • Level 1 - Fallback ⏺
        • Level 2 - Fallout ⏺
        • Level 3 - Coin Flip ⏺⏺
        • Level 4 - Telephone ⏺
        • Level 5 - Token ⏺⏺
        • Level 6 - Delegation ⏺⏺
        • Level 7 - Force ⏺⏺⏺
        • Level 8 - Vault ⏺⏺
        • Level 9 - King ⏺⏺⏺
        • Level 10 - Re-entrancy ⏺⏺⏺
        • Level 11 - Elevator ⏺⏺
        • Level 12 - Privacy ⏺⏺⏺
        • Level 13 - Gatekeeper 1 ⏺⏺⏺⏺
        • Level 14 - Gatekeeper 2 ⏺⏺⏺
        • Level 15 - Naught Coin ⏺⏺⏺
        • Level 16 - Preservation ⏺⏺⏺⏺
        • Level 17 - Recovery ⏺⏺⏺
        • Level 18 - Magic Number ⏺⏺⏺
        • Level 19 - Alien Codex ⏺⏺⏺⏺
        • Level 20 - Denial ⏺⏺⏺
        • Level 21 - Shop ⏺⏺
        • Level 22 - Dex ⏺⏺
        • Level 23 - Dex Two ⏺⏺
        • Level 24 - Puzzle Wallet ⏺⏺⏺⏺
        • Level 25 - Motorbike ⏺⏺⏺
        • Level 26 - DoubleEntryPoint ⏺⏺
        • Level 27 - Good Samaritan ⏺⏺⏺
        • Level 28 - Gatekeeper 3 ⏺⏺⏺
        • Level 29 - Switch ⏺⏺⏺⏺
        • Level 30 - Higher Order ⏺⏺⏺⏺
        • Level 31 - Stake ⏺⏺⏺
      • 💸Damn Vulnerable DeFi
    • 🔍Auditing
      • 🗞️Exploit Resources
      • 🔧Audit Tools
    • 🤖MEV
  • Infrastructure Docs
    • 💻Hardware
    • 🐧Linux
      • 📖Linux Glossary
      • ⌨️Linux Commands
      • 💾Installation
      • 🏗️Maintenance
      • 🖥️Ubuntu Desktop
      • 🛜ZeroTier
      • 🎞️TMUX
      • 🔵Bluetooth
    • ⛓️Ethereum Clients
      • ⚙️Execution Clients
        • ⛏️Geth
          • 💾Installation
          • ⌨️Useful Commands
          • 🏗️Maintenance
        • 🐻Erigon
          • 💾Installation
          • ⌨️Useful Commands
          • 🏗️Maintenance
        • 🧶Besu
          • 💾Installation
          • ⌨️Useful Commands
          • 🏗️Maintenance
      • 🤝Beacon Clients
        • 💡Lighthouse
          • 💾Installation
          • ⌨️Useful Commands
          • 🏗️Maintenance
        • 🪅Teku
          • 💾Installation
          • ⌨️Useful Commands
          • 🏗️Maintenance
      • 💎Validator Clients
        • 💡Lighthouse
          • 💾Installation
          • ⌨️Useful Commands
          • 🏗️Maintenance
      • ➕L2 Clients
        • 🔵Base
          • 💾Installation
          • ⌨️Useful Commands
          • 🏗️Maintenance
      • 💰MEV Boost
        • 💾Installation
        • 🏗️Maintenance
    • 🚨Alerting and Monitoring
      • 🔥Prometheus
      • 🌡️HealthChecks.io
      • 📟PagerDuty
  • General Dev
    • 💾Git Notes
      • Repos
      • Committing changes
      • Branches
      • Merging & Rebasing
      • PRs
Powered by GitBook
On this page
Edit on GitHub
  1. General Dev
  2. Git Notes

Branches

Formatting

  • Branch naming should be clear and use slashes e.g. routing/campground

  • So you can easily search for all branches of that type: git branch --list "routing/*"

Description
Commands

List all branches

  • q key to exit list

  • -avv more info in list (also shows hidden branches)

git branch

git branch -avv

Create a new branch

git branch <BRANCH_NAME>

Create a new branch and checkout at the same time

git checkout -b <BRANCH_NAME>

Change to a branch

  • switch also works for changing branches

git checkout <BRANCH_NAME>

git switch <BRANCH_NAME>

Checkout a specific commit rather than a whole branch

  • This moves HEAD to the specific commit

git checkout <COMMIT_HASH>

Relative references

  • Move up ancestors from a specific reference point

  • ^ moves to the first parent of the ref e.g.main^ and ^^ to the second parent, etc.

  • ^2 moves to the second parent if the current commit has two or more parents to move back towards

  • Use HEAD^ to travel backwards as the relative reference moves with you

  • ~ moves a specified number of commits backwards e.g. HEAD~4

  • I think ~ without a number is the same as ^

  • The modifiers can also be chained together in a single command!

git checkout <REF>^

git checkout HEAD^

git checkout HEAD^2

git checkout HEAD~4

git checkout HEAD~2^2~2

Moving a branch (Branch forcing) to a new location

  • -f forces the command to happen

git branch -f <BRANCH_TO_MOVE> <LOCATION_TO_MOVE>

Merge two branches

  • The branch name used should be the one you are not currently in

git merge <BRANCH_NAME>

Delete a branch

git branch -d <BRANCH_NAME>

Delete branch on Remote

git push <REMOTE_NAME> --delete <BRANCH_NAME>

List of changes that will be merged into the current branch

git log ..<BRANCH_NAME>

Formatting branch names

  • Branch naming should be clear and use slashes e.g. routing/campground

  • So you can easily search for all branches of that type

git branch --list "routing/*"

Remote tracking

  • You can make any arbitrary branch track o/main, and if you do so, that branch will have the same implied push destination and merge target as main

  • This means you can run git push on a branch named totallyNotMain and have your work pushed to the main branch on the remote!

  • There are two ways to set this property. The first is to checkout a new branch by using a remote branch as the specified ref

  • Another way to set remote tracking on a branch is to simply use the git branch -u option

    • <BRANCH_NAME> is not needed if you are already on the branch you want to use as the remote tracking reference

git checkout -b <NEW_BRANCH_NAME> <REMOTE_REF>

git checkout -b totallyNotMain origin/main git branch -u <REMOTE_REF> <BRANCH_NAME>

git branch -u origin/main foo

Deleting an ambiguous local branch

  • If you've made a mistake and somehow created a local branch with the same name as a remote branch, you can either rename the local branch or delete it in the local file system

rm -r .git/refs/heads/<BRANCH_TO_DELETE>

Last updated 2 months ago

💾