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
1450
votes
14 answers

Why there are two ways to unstage a file in Git?

Sometimes git suggests git rm --cached to unstage a file, sometimes git reset HEAD file. When should I use which? D:\code\gt2>git init Initialized empty Git repository in D:/code/gt2/.git/ D:\code\gt2>touch a D:\code\gt2>git status # On branch…
Senthess
  • 17,020
  • 5
  • 23
  • 28
1448
votes
16 answers

How to remove remote origin from a Git repository

I just did git init to initialize my folder as Git repository and then added a remote repository using git remote add origin URL. Now I want to remove this git remote add origin and add a new repository git remote add origin new-URL. How can I do…
Om3ga
  • 30,465
  • 43
  • 141
  • 221
1443
votes
12 answers

How can I know if a branch has been already merged into master?

I have a git repository with multiple branches. How can I know which branches are already merged into the master branch?
hectorsq
  • 74,396
  • 19
  • 43
  • 46
1434
votes
19 answers

How do I remove a single file from the staging area (undo git add)?

Situation: I have a Git repository with files already in the index. I make changes to several files, open Git and add these files to my staging area with "git add ." Question: How do I remove one of those files from the staging area but not remove…
PHLAK
  • 22,023
  • 18
  • 49
  • 52
1429
votes
24 answers

How to compare a local Git branch with its remote branch

How can I see the diff between a local branch and a remote branch?
mrblah
  • 99,669
  • 140
  • 310
  • 420
1421
votes
20 answers

.gitignore exclude folder but include specific subfolder

I have a folder application/, which I add to the .gitignore. Inside the application/-folder there is a folder application/language/gr. How can I include this folder? I've tried this: application/ !application/language/gr/
chchrist
  • 18,854
  • 11
  • 48
  • 82
1418
votes
12 answers

How do I diff the same file between two different commits on the same branch?

In Git, how could I compare the same file between two different commits (not contiguous) on the same branch (master for example)? I'm searching for a compare feature like the one in Visual SourceSafe (VSS) or Team Foundation Server (TFS). Is it…
systempuntoout
  • 71,966
  • 47
  • 171
  • 241
1415
votes
18 answers

Undo git pull, how to bring repos to old state

Is there any way to revert or undo git pull so that my source/repos will come to old state that was before doing git pull ? I want to do this because it merged some files which I didn't want to do so, but only merge other remaining files. So, I want…
seg.server.fault
  • 19,118
  • 13
  • 35
  • 31
1406
votes
14 answers

How can I undo pushed commits using git?

I have a project in a remote repository, synchronized with a local repository (development) and the server one (prod). I've been making some commited changes already pushed to remote and pulled from the server. Now, I want to undo those changes. So…
Manolo
  • 24,020
  • 20
  • 85
  • 130
1393
votes
42 answers

How to create a .gitignore file

I need to add some rules to my .gitignore file. However, I can't find it in my project folder. Isn't it created automatically by Xcode? If not, what command allows me to create one?
Luca
  • 20,399
  • 18
  • 49
  • 70
1385
votes
32 answers

What should be in my .gitignore for an Android Studio project?

What files should be in my .gitignore for an Android Studio project? I've seen several examples that all include .iml but IntelliJ docs say that .iml must be included in your source control.
respectTheCode
  • 42,348
  • 18
  • 73
  • 86
1384
votes
32 answers

Removing multiple files from a Git repo that have already been deleted from disk

I have a Git repo that I have deleted four files from using rm (not git rm), and my Git status looks like this: # deleted: file1.txt # deleted: file2.txt # deleted: file3.txt # deleted: file4.txt How do I remove these files…
Codebeef
  • 43,508
  • 23
  • 86
  • 119
1371
votes
9 answers

How to rebase local branch onto remote master

I have a cloned project from a master branch from remote repository remote_repo. I create a new branch and I commit to that branch. Other programmers pushed to remote_repo to the master branch. I now need to rebase my local branch RB onto…
Damir
  • 54,277
  • 94
  • 246
  • 365
1363
votes
18 answers

Filename too long in Git for Windows

I'm using Git-1.9.0-preview20140217 for Windows. As I know, this release should fix the issue with too long filenames. But not for me. Surely I'm doing something wrong: I did git config core.longpaths true and git add . and then git commit.…
Papa Mufflon
  • 17,558
  • 5
  • 27
  • 35
1357
votes
12 answers

Remove a git commit which has not been pushed

I did a git commit but I have not pushed it to the repository yet. So when I do git status, I get '# Your branch is ahead of 'master' by 1 commit. So if I want to roll back my top commit, can I just do: git reset --hard…
hap497
  • 154,439
  • 43
  • 83
  • 99