khashf
1/11/2018 - 8:22 PM

git

git

git status It's healthy to run git status often. Sometimes things change and you don't notice it.

staged: Files are ready to be committed. unstaged: Files with changes that have not been prepared to be committed. untracked: Files aren't tracked by Git yet. This usually indicates a newly created file. deleted: File has been deleted and is waiting to be removed from Git.

add all: You can also type git add -A . where the dot stands for the current directory, so everything in and beneath it is added. The -A ensures even file deletions are included. git reset: You can use git reset to remove a file or files from the staging area. (to unstage a file)

Staging Area: A place where we can group files together before we "commit" them to Git. Commit A "commit" is a snapshot of our repository. This way if we ever need to look back at the changes we've made (or if someone else does), we will see a nice timeline of all changes.

Check all the things! When using wildcards you want to be extra careful when doing commits. Make sure to check what files and folders are staged by using git status before you do the actual commit. This way you can be sure you're committing only the things you want.

Use git log --summary to see more information for each commit. You can see where new files were added for the first time or where files were deleted. It's a good overview of what's going on in the project.

git remote: Git doesn't care what you name your remotes, but it's typical to name your main one origin.

Cool Stuff: When you start to get the hang of git you can do some really cool things with hooks when you push. For example, you can upload directly to a webserver whenever you push to your master remote instead of having to upload your site with an ftp client. Check out Customizing Git - Git Hooks for more information.

Branching Branches are what naturally happens when you want to work on multiple features at the same time. You wouldn't want to end up with a master branch which has Feature A half done and Feature B half done. Rather you'd separate the code base into two "snapshots" (branches) and work on and commit to them separately. As soon as one was ready, you might merge this branch back into the master branch and push it to the remote server.

Pull Requests If you're hosting your repo on GitHub, you can do something called a pull request. A pull request allows the boss of the project to look through your changes and make comments before deciding to merge in the change. It's a really great feature that is used all the time for remote workers and open-source projects. Check out the pull request help page for more information.

Force delete What if you have been working on a feature branch and you decide you really don't want this feature anymore? You might decide to delete the branch since you're scrapping the idea. You'll notice that git branch -d bad_feature doesn't work. This is because -d won't let you delete something that hasn't been merged. You can either add the --force (-f) option or use -D which combines -d -f together into one command.

a branch is not available to others unless you push the branch to your remote repository git push origin

git tries to auto-merge changes. Unfortunately, this is not always possible and results in conflicts. You are responsible to merge those conflicts manually by editing the files shown by git. After changing, you need to mark them as merged with git add before merging changes, you can also preview them by using git diff <source_branch> <target_branch>