Questions tagged [git]

Git is an open-source distributed version control system (DVCS). Use this tag for questions related to Git usage and workflows. DO NOT USE the [github] tag for Git-related issues simply because a repository happens to be hosted on GitHub. Also, do not use this tag for general programming questions that happen to involve a Git repository.

Filter by
Sorted by
Tagged with
6724
votes
30answers
1.7m views

How can I make Git "forget" about a file that was tracked, but is now in .gitignore?

There is a file that was being tracked by Git, but now the file is on the .gitignore list. However, that file keeps showing up in git status after it's edited. How do you force Git to completely ...
7620
votes
41answers
7.7m views

How do I revert a Git repository to a previous commit?

How do I revert from my current state to a snapshot made on a certain commit? If I do git log, then I get the following output: $ git log commit a867b4af366350be2e7c21b8de9cc6504678a61b` Author: Me &...
864
votes
20answers
319k views

How to remove/delete a large file from commit history in the Git repository?

I accidentally dropped a DVD-rip into a website project, then carelessly git commit -a -m ..., and, zap, the repo was bloated by 2.2 gigs. Next time I made some edits, deleted the video file, and ...
23474
votes
99answers
10.2m views

How do I undo the most recent local commits in Git?

I accidentally committed the wrong files to Git, but didn't push the commit to the server yet. How can I undo those commits from the local repository? The only way seems to be to copy the edits in ...
71
votes
1answer
23k views

How do I add files in Git to the path of a former submodule?

I have a project that used to contain a submodule, at path mysubmodule. I installed the latest Git from source (1.8.3-rc2) and ran git submodule deinit mysubmodule. I then deleted the .gitmodules ...
241
votes
8answers
356k views

How can I move HEAD back to a previous location? (Detached head) & Undo commits

In Git, I was trying to do a squash commit by merging in another branch and then resetting HEAD to the previous place via: git reset origin/master But I need to step out of this. How can I move HEAD ...
5122
votes
39answers
3.1m views

How to resolve merge conflicts in a Git repository?

I want to resolve merge conflicts in my Git repository. How can I do that?
2666
votes
21answers
790k views

Ignore files that have already been committed to a Git repository [duplicate]

I have an already initialized Git repository that I added a .gitignore file to. How can I refresh the file index so the files I want ignored get ignored?
18621
votes
41answers
9.4m views

How do I delete a Git branch locally and remotely?

I want to delete a branch both locally and remotely. Failed Attempts to Delete a Remote Branch $ git branch -d remotes/origin/bugfix error: branch 'remotes/origin/bugfix' not found. $ git branch -d ...
1866
votes
26answers
286k views

Detach (move) subdirectory into separate Git repository

I have a Git repository which contains a number of subdirectories. Now I have found that one of the subdirectories is unrelated to the other and should be detached to a separate repository. How can I ...
1667
votes
22answers
1.1m views

How do I clone a subdirectory only of a Git repository?

I have my Git repository which, at the root, has two sub directories: /finisht /static When this was in SVN, /finisht was checked out in one place, while /static was checked out elsewhere, like so: ...
2652
votes
39answers
959k views

How to change the author and committer name and e-mail of multiple commits in Git?

I was writing a simple script on the school computer, and committing the changes to Git (in a repo that was in my pen drive, cloned from my computer at home). After several commits, I realized I was ...
437
votes
11answers
157k views

Remove sensitive files and their commits from Git history

I would like to put a Git project on GitHub but it contains certain files with sensitive data (usernames and passwords, like /config/deploy.rb for capistrano). I know I can add these filenames to ....
429
votes
13answers
276k views

Why did my Git repo enter a detached HEAD state?

I ended up with a detached head today, the same problem as described in: git push says everything up-to-date even though I have local changes As far as I know I didn't do anything out of the ordinary,...
4802
votes
36answers
1.2m views

How can I add a blank directory to a Git repository?

How can I add a blank directory (that contains no files) to a Git repository?
854
votes
37answers
727k views

Git for beginners: The definitive practical guide

Ok, after seeing this post by PJ Hyett, I have decided to skip to the end and go with Git. So what I need is a beginner's practical guide to Git. "Beginner" being defined as someone who knows how to ...
4378
votes
39answers
2.4m views

Squash my last X commits together using Git

How can I squash my last X commits together into one commit using Git?
41
votes
2answers
6k views

What exactly do we mean by "branch"?

Long story short... As far as I can tell, the term "branch" (in Git parlance) may refer to related but different things: a non-symbolic reference/pointer to a commit, the name of such a reference (e....
1989
votes
24answers
1.0m views

Is there a way to cache https credentials for pushing commits?

I recently switched to synchronizing my repositories to https:// on GitHub (due to firewall issues), and it asks for a password every time. Is there a way to cache the credentials, instead of ...
428
votes
8answers
194k views

Checkout another branch when there are uncommitted changes on the current branch

Most of the time when I try to checkout another existing branch, Git doesn't allow me if I have some uncommitted changes on the current branch. So I'll have to commit or stash those changes first. ...
981
votes
6answers
321k views

Definition of "downstream" and "upstream"

I've started playing with Git and have come across the terms "upstream" and "downstream". I've seen these before but never understood them fully. What do these terms mean in the context of SCMs (...
12887
votes
38answers
3.1m views

What is the difference between 'git pull' and 'git fetch'?

What are the differences between git pull and git fetch?
1872
votes
25answers
564k views

How do you merge two Git repositories?

Consider the following scenario: I have developed a small experimental project A in its own Git repo. It has now matured, and I'd like A to be part of larger project B, which has its own big ...
211
votes
4answers
67k views

Can git automatically switch between spaces and tabs?

I use tabs for indentation in my python programs, but I would like to collaborate (using git) with people who use spaces instead. Is there a way for git to automatically convert between spaces and ...
259
votes
4answers
293k views

Git submodule update

I'm not clear on what the following means (from the Git submodule update documentation): ...will make the submodules HEAD be detached, unless --rebase or --merge is specified... How does --rebase/-...
890
votes
12answers
696k views

How can I specify a branch/tag when adding a Git submodule?

How does git submodule add -b work? After adding a submodule with a specific branch, a new cloned repository (after git submodule update --init) will be at a specific commit, not the branch itself (...
5
votes
1answer
5k views

Egit in eclipse missing tree

Looks like I have a missing tree error. Just to be fair, I did totally just mess up my local files on git and got fed up and did a complete hard disk delete on my repo and recloned from remote master. ...
1204
votes
19answers
480k views

.gitignore exclude folder but include specific subfolder

I have the folder application/ which I add to the .gitignore. Inside the application/ folder is the folder application/language/gr. How can I include this folder? I've tried this application/ !...
1931
votes
20answers
802k views

How to stop tracking and ignore changes to a file in Git?

I have cloned a project that includes some .csproj files. I don't need/like my local csproj files being tracked by Git (or being brought up when creating a patch), but clearly they are needed in the ...
848
votes
38answers
1.2m views

Remove credentials from Git

I'm working with several repositories, but lately I was just working in our internal one and all was great. Today I had to commit and push code into other one, but I'm having some troubles. $ git ...
556
votes
2answers
95k views

Git - Difference Between 'assume-unchanged' and 'skip-worktree'

I have local changes to a file that I don't want to commit to my repository. It is a configuration file for building the application on a server, but I want to build locally with different settings. ...
265
votes
4answers
105k views

Multiple working directories with Git?

I'm not sure if this is something supported by Git, but in theory it seems like it should work to me. My workflow often involves my editing of files in multiple branches simultaneously. In other ...
3721
votes
34answers
3.2m views

Delete commits from a branch in Git

I would like to know how to delete a commit. By delete, I mean it is as if I didn't make that commit, and when I do a push in the future, my changes will not push to the remote branch. I read git ...
7656
votes
27answers
2.9m views

How to modify existing, unpushed commit messages?

I wrote the wrong thing in a commit message. How can I change the message? The commit has not been pushed yet.
8328
votes
47answers
6.2m views

How do I force "git pull" to overwrite local files?

How do I force an overwrite of local files on a git pull? The scenario is the following: A team member is modifying the templates for a website we are working on They are adding some images to the ...
788
votes
15answers
355k views

How can I pull/push from multiple remote locations?

The short: is there a way to have a git repo push to and pull from a list of remote repos (rather than a single "origin")? The long: I often have a situation when I'm developing an app in multiple ...
3935
votes
33answers
1.1m views

How do I remove a submodule?

How do I remove a Git submodule? By the way, is there a reason I can't simply do git submodule rm whatever ?
740
votes
10answers
413k views

How to cherry-pick a range of commits and merge them into another branch?

I have the following repository layout: master branch (production) integration working What I want to achieve is to cherry-pick a range of commits from the working branch and merge it into the ...
3750
votes
22answers
1.5m views

Make an existing Git branch track a remote branch?

I know how to make a new branch that tracks remote branches, but how do I make an existing branch track a remote branch? I know I can just edit the .git/config file, but it seems there should be an ...
4297
votes
31answers
989k views

How do I update or sync a forked repository on GitHub?

I forked a project, applied several fixes and created a pull request which was accepted. A few days later, another change was made by another contributor. So my fork doesn't contain that change. How ...
19
votes
3answers
24k views

Confused by git checkout

I am new to git and trying to wrap my head around the way branches work. According to the documentation git checkout Updates files in the working tree to match the version in the index or the ...
5111
votes
34answers
2.4m views

How can I reset or revert a file to a specific revision?

I have made some changes to a file which has been committed a few times as part of a group of files, but now want to reset/revert the changes on it back to a previous version. I have done a git log ...
420
votes
12answers
321k views

How do you fix a bad merge, and replay your good commits onto a fixed merge?

I accidentally committed an unwanted file (filename.orig while resolving a merge) to my repository several commits ago, without me noticing it until now. I want to completely delete the file from the ...
1836
votes
17answers
546k views

When do you use Git rebase instead of Git merge?

When is it recommended to use Git rebase vs. Git merge? Do I still need to merge after a successful rebase?
3198
votes
11answers
1.9m views

Difference between "git add -A" and "git add ."

The command git add [--all|-A] appears to be identical to git add .. Is this correct? If not, how do they differ?
1644
votes
35answers
927k views

Pretty Git branch graphs

I've seen some books and articles have some really pretty looking graphs of Git branches and commits. How can I make high-quality printable images of Git history?
2449
votes
31answers
689k views

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 ...
137
votes
3answers
22k views

Is git's semi-secret empty tree object reliable, and why is there not a symbolic name for it?

Git has a well-known, or at least sort-of-well-known, empty tree whose SHA1 is: 4b825dc642cb6eb9a060e54bf8d69288fbee4904 (you can see this in any repo, even a newly created one, with git cat-file -t ...
4434
votes
33answers
2.7m views

Undo a Git merge that hasn't been pushed yet

Within my master branch, I did a git merge some-other-branch locally, but never pushed the changes to origin master. I didn't mean to merge, so I'd like to undo it. When doing a git status after my ...
4934
votes
30answers
2.4m views

How to change the URI (URL) for a remote Git repository?

I have a repo (origin) on a USB key that I cloned on my hard drive (local). I moved "origin" to a NAS and successfully tested cloning it from here. I would like to know if I can change the URI of "...

1
2 3 4 5
361