Questions tagged [git]

Git is an open-source distributed version control system (DVCS). Use this tag for questions about Git usage and workflows. Do not use this tag for general programming questions that happen to involve a Git repository. Do not use this tag for GitHub/GitHub Actions questions that do not involve git usage; use [github] or [github-actions] instead. Do not use the [github] tag for Git-related issues just because a repository happens to be hosted on GitHub.

Git is an open-source distributed version control system () with an emphasis on speed. was initially designed and developed by Linus Torvalds for kernel development, now it is maintained by Junio Hamano.

Every Git working directory contains a full-fledged repository with complete history and full revision tracking capabilities, not dependent on network access or a central server.

The latest stable version is 2.40.0, released on 13 March, 2023.

Characteristics

  • Strong support for non-linear development
  • Distributed development
  • Compatibility with existing systems/protocols
  • Efficient handling of large projects
  • Cryptographic authentication of history
  • Toolkit-based design
  • Pluggable merge strategies
  • Garbage accumulates unless collected
  • Periodic explicit object packing
  • Data Assurance

Data structures

git - data workflow

External Links

Internal Links

Installation/Setup

Working with the code

Tagging, branching, releases, baselines

Git Clients

  • msysgit - Cross platform, included with Git
  • gitk - Cross platform history viewer, included with Git
  • RepoZ - Zero-effort repository hub to track and access local Git repositories for Windows and macOS
  • gitnub - macOS
  • gitx - macOS history viewer
  • smartgit - Cross platform, commercial, beta
  • tig - console GUI for Linux
  • qgit - GUI for Windows, Linux
  • Git Extensions - package for Windows, includes friendly GUI
  • SourceTree - A free Git & Mercurial client for Windows or macOS
  • posh-git - A Windows PowerShell environment for Git
  • TortoiseGit - A Windows Explorer extension with overlay icons representing the file statuses in explorer
  • GitKraken - A fancy, cross-platform Git client
  • GitHub Desktop — A cross-platform client, primarily used for GitHub but works with other hosts

Other Git beginner's references

There are also good guides if you would like to understand Git conceptually or if you would like to compare other revision control software such as subversion.

Free Git hosting

Video Tutorial

Related tags

Chat

The Stack Overflow git chat is useful for coordinating work within this tag, and perhaps occasionally for getting quick help (though no guarantees can be made; attendance is spotty).

150148 questions
2585
votes
51 answers

How do I delete all Git branches which have been merged?

How do I delete branches which have already been merged? Can I delete them all at once, instead of deleting each branch one-by-one?
Nyambaa
  • 38,988
  • 9
  • 29
  • 35
2560
votes
16 answers

How do I show the changes which have been staged?

I staged a few changes to be committed. How do I see the diffs of all files which are staged for the next commit? Is there a handy one-liner for this? git status only shows names of files which are staged, but I want to see the actual diffs. The…
Frerich Raabe
  • 90,689
  • 19
  • 115
  • 207
2553
votes
6 answers

What are the differences between .gitignore and .gitkeep?

What are the differences between .gitignore and .gitkeep? Are they the same thing with a different name, or do they both serve a different function? I don't seem to be able to find much documentation on .gitkeep.
Matty
  • 33,203
  • 13
  • 65
  • 93
2552
votes
19 answers

How do I revert all local changes in Git managed project to previous state?

I ran git status which told me everything was up to date and there were no local changes. Then I made several consecutive changes and realized I wanted to throw everything away and get back to my original state. Will this command do it for me? git…
Jacques René Mesrine
  • 46,127
  • 27
  • 66
  • 104
2551
votes
33 answers

How can I save username and password in Git?

I want to use a push and pull automatically in Git Extensions, Sourcetree or any other Git GUI without entering my username and password in a prompt, every time. So how can I save my credentials in Git?
Edson Cezar
  • 25,884
  • 5
  • 19
  • 27
2544
votes
31 answers

Do a "git export" (like "svn export")?

I've been wondering whether there is a good "git export" solution that creates a copy of a tree without the .git repository directory. There are at least three methods I know of: git clone followed by removing the .git repository directory. git…
Greg Hewgill
  • 951,095
  • 183
  • 1,149
  • 1,285
2536
votes
30 answers

Make .gitignore ignore everything except a few files

I understand that a .gitignore file cloaks specified files from Git's version control. How do I tell .gitignore to ignore everything except the files I'm tracking with Git? Something like: # Ignore everything: * # Do not ignore these…
Andrew
  • 36,541
  • 13
  • 67
  • 93
2527
votes
23 answers

Pull latest changes for all git submodules

We're using git submodules to manage a couple of large projects that have dependencies on many other libraries we've developed. Each library is a separate repo brought into the dependent project as a submodule. During development, we often want to…
Brad Robinson
  • 44,114
  • 19
  • 59
  • 88
2523
votes
22 answers

Branch from a previous commit using Git

If I have N commits, how do I branch from the N-3 commit?
dole doug
  • 34,070
  • 20
  • 68
  • 87
2491
votes
27 answers

How do I delete a file from a Git repository?

How can I delete "file1.txt" from my repository?
webminal.org
  • 44,948
  • 37
  • 94
  • 125
2420
votes
24 answers

How do I recover a dropped stash in Git?

I frequently use git stash and git stash pop to save and restore changes in my working tree. Yesterday, I had some changes in my working tree that I had stashed and popped, and then I made more changes to my working tree. I'd like to go back and…
Greg Hewgill
  • 951,095
  • 183
  • 1,149
  • 1,285
2386
votes
14 answers

Do I commit the package-lock.json file created by npm 5?

npm 5 was released today and one of the new features include deterministic installs with the creation of a package-lock.json file. Is this file supposed to be kept in source control? I'm assuming it's similar to yarn.lock and composer.lock, both of…
rink.attendant.6
  • 44,500
  • 61
  • 101
  • 156
2334
votes
21 answers

Showing which files have changed between two revisions

I want to merge two branches that have been separated for a while and wanted to know which files have been modified. Came across this link: http://linux.yyz.us/git-howto.html (moved to web.archive.org) which was quite useful. The tools to compare…
johannix
  • 29,188
  • 15
  • 39
  • 42
2316
votes
14 answers

How can I git stash a specific file?

How can I stash a specific file leaving the others currently modified out of the stash I am about to save? For example, if git status gives me this: younker % gst # On branch master # Your branch is ahead of 'origin/master' by 1 commit. # #…
ynkr
  • 25,946
  • 4
  • 32
  • 30
2316
votes
28 answers

How do I name and retrieve a Git stash by name?

How do I save/apply a stash with a name? I don't want to have to look up its index number in git stash list. I tried git stash save "my_stash_name", but that only changes the stash description, and the corresponding git apply "my_stash_name" doesn't…
Suan
  • 34,563
  • 13
  • 47
  • 61