Git commands

Problems, solutions and everything in between.
Latest entries

Make Git ignore a tracked file (Previously Committed)

If a file has previously been committed and you want said file to be 'ignored' just adding the file into .gitignore isn't enough, you have to explicitly tell Git to remove the file. If you run `git status` on the file that has been committed in the past but is now in the .gitignore, it will continue to appear. To stop tracking a file you need to remove it with git rm --cached

What does the “-u” do in git push -u origin master?

As simply put as can be, -u specifies the "upstream" git push -u origin master is the same as git push origin master; git branch --set-upstream master origin/master If you forget the "-u" when pushing your commit perform the last command git branch --set-upstream master origin/master Explained Upstream refers to the main repo that people will be pulling from. So when future you runs "git push" Git "Knows" where you want to push and pull from, meaning you can use "git push" and "git pull" without…

Combine git add and git commit into one command

Git add and commit in one command git config --global alias.a '!git add -A && git commit -m' // Run this first, once git a 'Your commit message' The above command combines git add and git commit, so you can now run the command git a 'Your commit message'

Security Flaw: Don’t leave a readable .git on the root of your server

Git has many different advantages, but one big security flaw that should be avoided is leaving a readable .git within you httpdocs/public_html. Let's say you have a folder structure like below. /httpdocs -> .git -> css/ -> js/ -> index.php Leaving a readable .git file will enable anyone to simply clone whatever is within the repository. We'll use Google for demonstrating purposes. git clone http://www.google.com Whatever has been committed to Git would now be cloned onto my machine without the…

Ignore files on commit with Git

List all branches in Git

Commit files in git

Commit changes to the head but not the remote repository ready for push git commit -m "Message to go with commit" Commit all files you've added with git add plus any changed files since then git commit -a

Add files to the staging area with Git

git add //Add a single file to git's staging area git add * Add all files to the staging area