Git is a version control system (VCS) for tracking changes in project directory and manage source code. It is free and open source. A complete long-term change history of every file. This means every change made by many individuals over the years. Git takes snapshots of a project, and stores those snapshots as unique versions. Git is designed for distributed development. If you’re involved with a project you can clone the project’s Git repository, and then work on it as if it was the only copy in existence. Every developer’s working copy of the code is also a repository that can contain the full history of all changes.
If you want to install the basic Git tools, go through Git installation URL There are many interfaces available for Git like GitHub, GitLab, Savannah, BitBucket, and SourceForge etc.
To start with Git need to make project directory as Git repository usually we called it as ‘Local Repository’.
Initializing a new repository: git init
To create a new repo, you’ll use the git init command. git init is a one-time command you use during the initial setup of a new repo. Executing this command will create a new .git sub-directory in your current working directory. This will also create a new master branch.
There are the level of configuration we can do, one is with –global option which basically works as the default configuration for all git repository setup on your system. Another one is with –local option which only applies to the repository where you are running this command.
git config user.name “FIRST_NAME LAST_NAME”
git config user.email “MY_NAME@example.com”
Basic Git commands that usually needs to perform Git operations:
To Cloning an existing repository: git clone.
git clone /path/to/repository
It used to create a copy or clone of remote repositories. When executed, the latest version of the remote repo files on the master branch will be pulled down and added to a new folder.
Local changes commands:
If files were modified then it will shows the list of files/directories which gets modified. Usually used to check the status of project files whether they modified or not.
Check the changes to tracked files. Used to check the difference between the last version of files and the current version of modified files.
Add current changes to the next commit.Usedto add the newly added or modified files to current branch.
git add <file_path>
To add all new and changed files to the staging area.
git add -A
Commit staged local changes in tracked files. Used to commit the recently added files to the branch and save changes to project/repository. Options we can use with : ‘-m’ to specify commit message.
To remove a file (or folder).
git rm -r [file-name.txt]
To store our changes when they are not ready to be committed and we need to change to a different branch.
Apply stash changes/files and drop on one command:
git stash pop
If you added a file by mistake, you can unstage it (but keep local changes).
git reset HEAD path/to/file
To check current branch and to display the git branch names list available.(the asterisk denotes the current branch).
To list all existing branches.(local and remote)
git branch -av
To switch from one to another branch.
git checkout <branch name>
To create and switch into new branch.
git checkout -b <new-branch name>
To remove all the modified changes from the specified file.
To merge a branch into the active branch. It simply merges one branch into parent or master branch. When your new feature is ready, you might want to integrate it into another branch (e.g.: prod or testing branch).
First, switch to the branch that is supposed to receive these changes. Then call “git merge” command with the name of the branch you want to integrate.
git merge <branch>
To integrate changes from one branch into another. It is an alternative to the better known “merge” command.
git rebase <branch>
Used to abort the rebasing operation.
git rebase –abort
To Continues the rebasing process only when all the conflicts get resolved.
git rebase –continue
UPDATE & PUBLISH Commands:
To pull the project/files/code from the remote location and to download and integrate remote changes. To integrate new changes from the remote repository. This will update your current HEAD branch with the new data from its counterpart branch on the remote. The changes will be directly merged into your local working directory.
To publish the committed changes on remote location. Options we can use with : ‘-f’ to forcefully publish changes.
git push <remote> <branch>
UNDO git operations:
git reset changes, where your current branch is pointing. The difference between –hard and –soft is whether or not your index is also modified. So, if we’re on branch master with this series of commits: – A – B – C (master)
HEAD points to C and the index matches C.
When we run git reset –soft B, master (and thus HEAD) now points to B, but the index still has the changes from C; git status will show them as staged. So if we run git commit at this point, we’ll get a new commit with the same changes as C.
It modifies your working directory. If we’re at C and run git reset –hard B, then the changes added in C, as well as any uncommitted changes you have, will be removed, and the files in your working copy will match commit B. Since you can permanently lose changes this way, you should always run git status before doing a hard reset to make sure your working directory is clean or that you’re okay with losing your uncommitted changes.
To Discard all local changes in your working directory. It removes all the files changes.
git reset –hard HEAD
To Discard local changes in a specific file. Restores all the changes to file up to the last commit.
git checkout HEAD <file>
Reset your HEAD pointer to a specific commit and discard all changes since then. Removes all the changes done after the commit ID specified in the command.
git reset –hard <commit>
To remove the commit but keep the committed changes to the staged area on the local repository.
git reset <commit>
COMMIT HISTORY Commands:
Show all commits, starting with latest commit information.
Show changes over time for a specific file.
git log -p <file>
Who changed what and when in <file>.
git blame <file>
Preview changes before merging.
git diff [source branch] [target branch]
Version Control Best Practices:
Commit Related Changes: A commit should be a wrapper for related changes. For example, fixing two different bugs should produce two separate commits.
Commit Often: It allows you to share your code more frequently with others. That way it’s easier for everyone to integrate changes regularly and avoid having merge conflicts.
Test Before You Commit: Resist the temptation to commit something that you “think” is completed. Test it thoroughly to make sure it really is completed and has no side effects (as far as one can tell).
Write Good Commit Messages: Begin your message with a short summary of your changes.
Use Branches: Branches are the perfect tool to help you avoid mixing up different lines of development. You should use branches extensively in your development workflows: for new features, bug fixes, experiments, ideas…
If you have any queries, questions or suggestions, feel free to share on firstname.lastname@example.org
Happy to help!
Aditya is the founder & managing partner at YuktaMedia. He has rich global experience in Digital Media having worked with large Publisher and Media Houses. That paired with deep technical knowledge of enterprise systems has let him found and lead YuktaMedia and create and drive the YuktaOne platform.
Other articles in the series
Discover how YuktaOne Media ERP addresses your Ad and Revenue Ops challenges
Schedule a free demo and learn from our Ad & Revenue operations experts.
YuktaMedia’s knowledgeable and experienced Ad Ops team has provided unparalleled support for Rotana sites by leveraging YuktaOne Media ERP for automated real-time reporting, revenue tracking, campaign pacing, performance and delivery.
Abir El Naboulsi
Sales Strategy Partner
“Working with the Yuktamedia team has given our company the extra support we needed to expand our business. The YuktaOne platform has reduced reporting hours significantly, allowing our internal team more time to focus on other initiatives. And our partners love having instant access to their data through a clean UI.
We’ve worked with several outsourced teams over the years and Yuktamedia stands out because of their dedication to our success. It isn’t just about completing a task, Aditya’s team cares about producing quality results.”
Business Operations & Strategic Partnerships | Digital Advertising
YuktaMedia has been an invaluable partner, helping us monitor our business KPIs with their platform. They build and maintain data connections quickly and they are very responsive to all our requests.
Senior Director, Global Operations
YuktaOne Media ERP has helped transform our client's business and has become an essential part of their ad and revenue operations. The Yukta team is knowledgeable, responsive and professional. We look to work with them whenever we can.
Founder and CEO
Our beloved Clients
We're equiped to serve you here
Are you a COVID-19 revenue impacted Publisher? Let's discuss Revenue challenges... Email us: email@example.com