Git is the undisputed king of source code management! However, it can be a little daunting for new users, especially as most developers and online guides favour the command line.
Thankfully, there are a set of common commands that cover 80% of my standard workflow.
Initialising your repository, updating the index, record changes and pushing to the remote.
git init git add . git commit -m "Initial Commit" git push origin <branch>
Clone a repository into a new directory.
git clone <repo_url> git clone -b <branch> <repo_url> git checkout -b <branch> origin/<branch>
Manage set of tracked repositories.
git remote git remote add origin <repo_url> git remote -v git remote rm origin
Fetch from and integrate with another repository or a local branch.
git pull https://github.com/teamname/reponame.git git pull https://github.com/teamname/reponame.git <branch> git pull origin <branch>
Branching is a powerful way to manage your code, I highly recommend following a branching methodology such as Git Flow.
git branch git branch <branch> git checkout <branch> git checkout -b <branch> git branch -m <newname> git branch -d <branch>
Join two or more development histories together.
git merge <branch>
Tag specific points in history.
git tag TAG_01 git push origin --tags
Lines of Code
Show lines of code in the active branch.
git ls-files | xargs wc -l
Show files that are ignored by Git.
git status --ignored
If you work on a Mac, you will probably also have pesky
.DS_Store files cluttering up your repository. To remove them run the following command (don’t forget to also add .DS_Store to your “.gitignore” file.
find . -name .DS_Store -print0 | xargs -0 git rm -f --ignore-unmatch