I thought I'd put together handy Git commands that I normally use on regular basis. I hope this will help you be more productive in developing your app or managing your codebases.
If you want to create a clean copy of a repository,
`git clone <LinkToGitHubRepo>`, creates a local copy of the repository
`git pull`, fetches and merges changes from the remote branch to local branch
To learn more about the branches in the repository,
`git branch --all`, views all local and remote branches
`git branch -vv`, checks the local branch's upstream
If you want to create / delete a remote branch to save, share, and collaborate with other developers,
This is handy for running tests on previous revision (back-tracking),
`git checkout <FirstSevenCharactersOfSHAID> -b <LocalBranchName>`, ** -b creates a new local branch, checks out a particular revision using Git SHAID. I usually use the SHAID as the Branch Name when running tests.
If you want to revert changes,
`git revert <ShaID>`, reverts a particular commit SHA
`git checkout --<NameOfFile>`, checks out the original file from the remote branch
`git reset --hard HEAD`, resets the local branch to it’s original state
Finding who modified a particular line of code / file
`git blame <NameOfFile>` , go to the line(s) of code that you are tracing the history of, git will show you the author’s credential and the SHAID.
** Fetch (`git fetch`) the latest code to see the latest committer.
Stashing changes to move to different branch
Cherry-picking -- porting commits from one branch to the other
Finding all commit related to particular project or topic
`git log --grep=”<keyword>”`
`git log --grep="<ProjectIDHere>"`, returns any related commit to that particular Project ID (Project Management App ID)
`git log --author="<NameofTeamMemberHere>"`, returns any related commit that person checked in that repository (checkout --since to add filter)
To squash changes in single commit,
`git rebase -i`, follow the prompt to accomplish your objective. I normally use this to squash multiple local commits into a single commit prior to committing to the central repository
If you want to understand the fundamentals and strategies, this is the book that I read and would recommend "Version Control with Git" by O'Reilly Media. However, there are many more new commands that have been implemented since. Your best bet would be to browse their man page.
While these handy commands are convenient to have, you may want to checkout Atlassian’s ‘Source Tree’ plugin. It is convenient to those who are GUI oriented.
Please do not hesitate to reach out if you need help with branching and release strategy as well as training your team using Git. I am glad to help!
** You can get a couple of free books on Audible when you sign up using this link! Keep Learning. Keep having #funventures!
World Traveler | Business Owner | Mentor
Sharing her life experiences, passion for art, and technology.