Categories

Category cover

Automation
155 posts

Category cover

Learning paths
119 posts

Category cover

CISO
22 posts

Category cover

Security
20 posts

Category cover

Notes
19 posts

Category cover

Personal Security
18 posts

Category cover

Infrastructure
12 posts

Category cover

OT/ICS
5 posts

Category cover

Books
3 posts

Category cover

UNetLab
3 posts

Category cover

Write-up
3 posts

Category cover

OSInt
2 posts

Category cover

My life
1 posts

Advanced Git commands

Andrea Dainese
September 19, 2024
Post cover

In the last two posts, we covered most of the essential Git features. Now, let’s dive into some additional functionalities that might come i

In the last two posts, we covered most of the essential Git features. Now, let’s dive into some additional functionalities that might come in handy.

.gitignore

The .gitignore file is used to specify which files or directories should never be included in your Git repository. This file is tailored to each repository and typically excludes:

  • Cache files
  • Compiled files
  • Temporary files
  • Password files

You can either start with GitHub’s suggested templates  or create your own using the correct format .

Stashing your work

Sometimes you need to put aside your current work to focus on something more urgent. If you’ve made changes but aren’t ready to commit, switching branches won’t work because Git doesn’t know how to handle uncommitted changes.

This is where stash comes in. It saves all your changes, including those staged for commit, and allows you to retrieve them later:

Now you can safely switch branches. To retrieve the stashed changes later:

You can also list all stashed changes with:

Deleting Remote Branches

While local branches can be deleted with the branch command, deleting a remote branch involves a push:

Rebase

Rebase lets you integrate changes in a way similar to merge, but it reapplies a series of commits starting from a different base, effectively rewriting the history of the repository. Be cautious, this can cause inconsistencies, especially in public repos where multiple people collaborate.

For example, in a repo with main and branches fix3 and fix4 waiting to be merged:

If we merge the fix3 branch, we notice that the commit IDs have been preserved:

Continue reading the post on Patreon .