Essential Git Commands for Software Development
If you're a seasoned developer or if its day one on the job understanding and mastering the Git is very essential! Git commands are literally your best friend whether it be for tracking code changes, working with others, or managing project workflows efficiently!
So what is Git and WHY should you use it?
Ahh Git! Git is a great control tool that helps developers manage project files and it keeps a history of all the changes you're making. It doesn't matter whether you're working by yourself or with a colleague. Git makes code management super smooth lets learn the tools needed to do so!
First steps
Navigating Directories
- pwd: Will display the current directory you're in.
- cd (directory name): Changes your working directory to the one you want.
- cd ..: Also moves you up one directory level.
Files and Folders
- ls: Will list all files and directories in that current location.
Creating Directories/Files
- mkdir (directory name): This makes a new directory.
- touch (file name): This will create a new empty file.
The Basic Core Commands
I'm a BIG believer in fundamentals and getting set up for success!
git init: To initialize a new Git Repository.
git config --global user.email IE: "youremail@example.com": To make your email for commits.
git config --list: This is to verify your Git settings.
Let's get you set up!
git add (file): This stage changes to a specific file.
git add .: Is the stage all changes in the directory.
git commit -m "Your Message": This commit is staged changes with a message.
git commit --amend: Use this if you need to change or modify the message or to include missing files.
Lets make changes!
- git status: So you can see which files have changes.
git diff: This compares working directory changes.
git log: To view the commit history.
Branching and Merging
- git branch: List all branches or if you need to create a new branch.
git checkout (branch name): This is to switch to a branch.
git checkout -b (branch name): This is to create and switch to a new branch in ONE step!
git merge (branch name): This merges another branch into your current one.
git branch -d (branch name): This will delete the entire branch.
Teamwork Remote Repositories
- git remote add (person) (url): This will link your local repo to a remote repo [This is my current link to a colleague to see who you're connected to use git remote -v]
- git push origin (branch name): This will upload the changes you made to a remote branch.
- git pull: This will merge changes from a colleague or any remote branch you're connected to.
- git fetch: You can get updates from a colleague or any remote branch you're connected to without merging.
Other Helpful Git Commands
- git clone: This will clone an existing repo.
- rm (file name): This will delete a file.
rmdir (directory name): This will remove an empty directory.
ls -a: This will list all the files even the hidden ones!
Thats all Folks!
All the git commands listed above will help you navigate your role as a developer. You'll gain more control over your code and work flow whether its the simple commands or the more advanced ones! Use it to your benefit lets work smarter not harder!
Sources
https://cloudstudio.com.au/2021/06/26/git-command/
https://parade.com/947443/parade/best-friend-quotes/
https://www.cert-india.com/belbin-stack/leadership-and-teams
https://www.facebook.com/thebasics14/?locale=is_IS
https://education.github.com/git-cheat-sheet-education.pdf
https://www.nytimes.com/2009/01/01/garden/01clones.html
https://www.archive360.com/blog/when-is-it-ok-to-delete-data
Top comments (0)