Lädt...

🔧 [Git] 5 Git Tips I Learned Today


Nachrichtenbereich: 🔧 Programmierung
🔗 Quelle: dev.to

How to Stop Tracking Unnecessary Files in Git

While working on a team project, I noticed that the .idea/ folder kept being tracked by Git. This folder contains IDE-generated metadata and configuration files, which don't need to be pushed to the remote repository.

Even if .idea/ is listed in .gitignore, Git might still track it if the folder was already added before the .gitignore rule was applied.

To stop tracking the folder without deleting the actual files, run:

git rm --cached -r .idea/

This removes the folder from Git's index without affecting the local files.

After running the command, you should see output like this:

delete '.idea/fileName.xml'
...

Useful Things I Learned

  • Hidden folders like .idea/ won't show up with ls. Use ls -a to see all hidden files and folders.
  • The .gitignore file needs to be in the root directory of the project, not inside subfolders.
  • The /out folder, which stores compiled binaries or build artifacts, should also be excluded from the repository since these files can be regenerated from the source code.

Discard Local Changes and Sync with Another Branch

If you want to discard all local changes and sync your branch with the latest version of another branch, use:

git reset --hard origin/<branch_name>

This command completely resets your branch to match the remote branch, deleting any local changes.

Setting IntelliJ as the Default Merge Conflict Tool

If you're not comfortable resolving merge conflicts from the command line, IntelliJ can be used to visually resolve conflicts.

On Mac:

git config --global merge.tool intellij
git config --global mergetool.intellij.cmd "/Applications/IntelliJ IDEA.app/Contents/MacOS/idea diff $LOCAL $REMOTE $BASE $MERGED"
git config --global mergetool.prompt true

On Windows:

git config --global merge.tool intellij
git config --global mergetool.intellij.cmd "C:/Program Files/JetBrains/IntelliJ IDEA/bin/idea64.exe" diff $LOCAL $REMOTE $BASE $MERGED
git config --global mergetool.prompt true

To verify the configuration:

git config --global --list | grep merge.tool

When a conflict occurs, run:

git mergetool

IntelliJ will display the conflicting files. The left pane shows the local changes (HEAD), and the right pane shows the incoming changes from the remote branch. After resolving conflicts, click Accept and commit the merge result:

git add .
git commit -m "Resolved merge conflicts"

Viewing Git Diff in IntelliJ

To set IntelliJ as the default diff tool:

git config --global diff.tool intellij
git config --global difftool.intellij.cmd "/Applications/IntelliJ\ IDEA.app/Contents/MacOS/idea diff $LOCAL $REMOTE"

Use this command to see differences in IntelliJ:

git difftool

IntelliJ will open each file one by one, showing the changes side-by-side.

Connecting an Existing Local Branch to a Remote Branch

If you create a local branch without pushing it to the remote repository, you'll need to connect it manually.

First, push the branch to the remote repository:

git push origin <branch_name>

Then, set the upstream branch:

git branch --set-upstream-to=origin/<branch_name>

If the remote branch doesn't show up immediately, run:

git fetch

You can verify the remote branches with:

git branch -r

This ensures your local branch is properly tracking the remote branch.

...

🔧 [Git] 5 Git Tips I Learned Today


📈 35.95 Punkte
🔧 Programmierung

🔧 20 Git Tips for 20 Years of Git


📈 18.47 Punkte
🔧 Programmierung

📰 Level up your git knowledge with these 10 useful tips to browse git history


📈 18.47 Punkte
🔧 AI Nachrichten

🔧 DAY 5 Git rebase, Git stash, Git cherry-pick.


📈 17.69 Punkte
🔧 Programmierung

🔧 Git Rebase and Git stash and Git pop -day 4


📈 17.69 Punkte
🔧 Programmierung

🔧 Ditch Git Checkout: Use Git Switch and Git Restore Instead


📈 17.69 Punkte
🔧 Programmierung

🔧 Restaurando e Alternando Branches com Git: Domine os Comandos git restore e git switch


📈 17.69 Punkte
🔧 Programmierung

🎥 Top Git Commands | Most Used Git Commands | Git Commands With Examples


📈 17.69 Punkte
🎥 Video | Youtube

🔧 git switch and git checkout – How to switch branches in git


📈 17.69 Punkte
🔧 Programmierung

🔧 Today I Learned


📈 17.49 Punkte
🔧 Programmierung

🐧 Today I learned that the Sony Playstation 3 Eye camera somehow works on linux.


📈 17.49 Punkte
🐧 Linux Tipps

🔧 What I Learned Today: Exploring JavaScript, TypeScript, Node.js, and Project Updates


📈 17.49 Punkte
🔧 Programmierung

🔧 Today I Learned...


📈 17.49 Punkte
🔧 Programmierung

🐧 Today I learned How to Freeze Ubuntu By Pressing F11


📈 17.49 Punkte
🐧 Linux Tipps

🔧 Today I learned - Ruby : Data Types and Variables


📈 17.49 Punkte
🔧 Programmierung

🔧 Today I Learned


📈 17.49 Punkte
🔧 Programmierung

🪟 Everything we learned about Xbox Series X today


📈 17.49 Punkte
🪟 Windows Tipps

🔧 hey everyone Today i learned html5


📈 17.49 Punkte
🔧 Programmierung

🔧 Today I Learned


📈 17.49 Punkte
🔧 Programmierung

🔧 TIL: Today I Learned Sinatra


📈 17.49 Punkte
🔧 Programmierung

🐧 Today I learned Open Source means never achieving a Return on Investment...Royal TS


📈 17.49 Punkte
🐧 Linux Tipps

🔧 Today I learned about Variables in PHP


📈 17.49 Punkte
🔧 Programmierung

🔧 What I Learned Today: Cleaning, Aggregating, and Visualizing Data with Python 🐍


📈 17.49 Punkte
🔧 Programmierung

🔧 3 things I'd do differently if I learned to code today


📈 17.49 Punkte
🔧 Programmierung

🐧 Today I learned about sudoers -- Wait here me out!


📈 17.49 Punkte
🐧 Linux Tipps

🔧 Today I learned: HTML and CSS


📈 17.49 Punkte
🔧 Programmierung

🐧 Today I learned about sudoers -- Wait here me out!


📈 17.49 Punkte
🐧 Linux Tipps

🔧 [Sparta Coding Club] DSA - Reflections - Today I learned


📈 17.49 Punkte
🔧 Programmierung

🔧 Today learned object create, calling statement, method definition, arguments(parameters)


📈 17.49 Punkte
🔧 Programmierung

🔧 What I learned today 5.8.24


📈 17.49 Punkte
🔧 Programmierung

matomo