git initCreates a new git repository in the directory
git add <file name>Adds a specific file to staging
git add .or
git add -AAdds the full directory and its contents to staging
git commit -m 'Commit message here'Commits the file changes in staging and provides a description for the commit
git diff*Analyze the differences between old files and ones that have been added to staging *
git branchView all local branches
git branch -b <branch name>Create a new branch and check into it
git branch -avView all branches local and remote
git checkout <branch name>Switch into the specified branch
git branch -d <branch name>Delete a specific branch
git push origin <branch name>Push a branch to a remote repository
git merge <branch name>Merge branch into master branch (ensure that you're inside the master branch)
git stashStashes changes in the .git file for temporaily hiding changed elements (make sure to run
git addprior to stashing
git stash applyReturns the stashed items
git logView previous commits, their messages, and ids
git log <file name>View who changed a specific file
git blame <file name>View who changed a specific file
git reset --hard HEADRemove all changes and revert to the previous commit
git checkout <file name>Remove changes made to a specific file, reverting it back to the previous commit
When you encounter a merge conflict, first... don't freak out. This just means you're being given the ability to choose which code you want to choose to go with.
git pullon a repo that has changes that conflict with your local copy.
error: The following untracked working tree files would be overwritten by merge: README.md Please move or remove them before you merge. Aborting
It's actually not that hard to fix merge conflicts, simply run
git statusand it will show you where the conflict exists. An example conflict might look like this:
<<<<<<< HEAD # Git Homepage ======= # git-guide > A guide for working with git >>>>>>> a1dfac148fb86311a453a9de338e4d7b9389ade5
>>>>>>> symbols are simply showing you where the conflict is. You have the choice to pick what you want to keep, what you want to remove, etc. After picking out the implementation that you want you can run:
git add .
git commit -m 'some commit message'
And you will be good to go.
git clone <link to repo>Clone a repository from a remote source, such as GitHub
git rebase masterWhile working on a branch you can bring in committed changes from another branch. This is helpful for ensuring that your feature branch can be cleanly merged with the master branch
I've been a software engineer for the past decade and have traveled the world building applications and training individuals on a wide variety of topics.